8

Using QGIS (2.14) is it possible on the data form for an attribute to have a colour (or other formatting) based on its value?

For example if my data has a field 'quality' which has a value 'good' or 'medium' or 'bad'. I'd like the field in the attribute form to show up green/orange/red depending on this value.

I'd be happy with a workaround - for example a symbol or icon that appears beside the field, coloured background to the field, and so on.

I'm happy to use QT Designer to create the data form. I'm happy to edit the form xml by hand. I'll struggle if the answer is that I need to use more than a line or two of Python code so I'm probably looking for answers which don't require this.

I also need the formatting to show up whether or not the layer is in edit mode (because the main data I'm using won't be editable).

EDIT: Note that I'm only looking for solutions that work for a QGIS data form, not on the attribute table, and not on exported data. The aim is to make data as easy to understand as possible, so a user working with the identify tool can quickly see/understand key information about a feature shown on the map. The real data I'm working with is complex and front-line users need to be assisted to understand it.

image of simple data form

  • I would export it as an excel sheet and color it in there. But I don't know if this is a workaround you could live with – JoeBe Oct 3 '17 at 0:43
  • Thanks JoeBe - no that's not what I'm looking for. And just as indicated by @ahmadhanb there are already capabilities that QGIS has to style the attribute table. What I need is to improve the usability of the data form so that QGIS can be utilised as an effective way to inspect data (one feature at a time). – Rostranimin Oct 3 '17 at 10:25
  • Perhaps you could tell the users to open attribute table and then select "show selected objects" (or how it is called). Once you set the styling of the attribute table (as explained by @ahmadhanb) the user can see one object at a time – JoeBe Oct 3 '17 at 11:08
3

If I understand you very well you can do an attribute table formatting using the following steps:

  1. Open you attribute table
  2. Use Conditional Formatting Rules

enter image description here

  1. Select the field the you want to apply the formatting rules from the drop-down list. In this example, I want to use a field name "Test"

enter image description here

  1. Select New Rule
  2. Select New expression, write the expression you want "Field name" = 'Very High', and in the Background choose the color you like and press Done

enter image description here

  1. Repeat step 5 for other conditions and give them different background colors as you can see below:

enter image description here

Here is the final results:

enter image description here

I am using QGIS 2.14.17 LTR

  • Thanks. I'm aware of this, and it's very useful, but it's the data FORM not the attribute table that I need to add a style to. – Rostranimin Oct 3 '17 at 10:01
  • 1
    @Rostranimin No, there is no way to apply the rule based style to data FORM. This option is only applied to the attribute table. As JoeBe the only option you have is Excel. – ahmadhanb Oct 3 '17 at 10:06
  • are you sure that this can't be done using a form created using QT/QT Designer? I can see that it can't be done as a native/simple function of QGIS - using the automatically produced data form - but I'm pretty sure that this could be done with much more advanced scripting etc... so really what I'm asking is whether it can be done in a simple enough way that someone like me would be capable, simply in the settings available using QT Designer. – Rostranimin Oct 3 '17 at 10:23
  • I am not sure if it is possible to do what you want using QT/QT Designer. But, from my experience and based on GIS.SE policy, if you want it to be done using a script, in this case you need to write your own script and ask for help if you stuck somewhere in your code. Otherwise, you question will be closed as off-topic. – ahmadhanb Oct 3 '17 at 10:31
  • Thanks. I appreciate that. I suspect that it may be possible with relatively simple settings in QT Designer though - and that I just don't know what these settings are. Really the question is whether this is the case - or whether it does indeed require more advanced scripting. The answer may indeed be 'no it can't be done without more advanced scripting'. I'll be happy enough to know this. – Rostranimin Oct 3 '17 at 10:40
2

I dont have the expertise to answer (or the reputation to post the link as a comment) but at this link https://nathanw.net/2011/09/05/qgis-tips-custom-feature-forms-with-python-logic/, Nathan Woodrow explain how it could be done (the colors part is near the bottom of the page). So it definitely could be done but I'am afraid it involve much Python....

  • Thanks. Yes I'd noticed that post. That's what makes me think that an advanced solution is possible. I thought that it may be possible to do something short of this - you can use QT Designer to set up relatively simple data forms pretty simply (no need to do any coding). I have that working nicely. What I don't know is whether what I'm asking is much more advanced, or whether there's a simple setting for it... – Rostranimin Oct 3 '17 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.