3

I would like to create a multi-field label based on an expression where the different fields will have different colors. Using an icon font, this will allow me to get this kind of result (done with ArcGIS):

enter image description here

I tried using similar expressions in QGIS, changing format to get it "QGIS compatible", but it doesn't work (ArcGIS code: <CLR red='130' green='130' blue='130'> & [RURAL] & [URBAN] & [CAMP] & </CLR>.

It seems it was not possible in previous version, I just tried with 3.10... but still the same.

However it's possible in the print composer to use html tags to define colors. So am I missing something to make it work on data label also ?

2
  • did you see something in the change log to suggest it would be possible? if not this is just a duplicate of gis.stackexchange.com/questions/242864/…
    – Ian Turton
    Mar 6 '20 at 14:55
  • Sorry, I didn't check the log. I just went through it and nothing about it so I guess it's still not possible.
    – m_beeckman
    Mar 11 '20 at 8:32
2

It is possible to change the colour of your icon (or font marker symbol) in Qgis (also with versions elder then 3.10).

Go to Symbology > create your "font marker" symbol and in the option Colour click in the right icon to add a variable > select edit and add the following expression

case 
when "field"  =  'no'  then '255,13,1' -- RGB red
when "field"  = 'ok'  then '255, 141, 1' -- RGB green
when "field"  =  'maybe'  then '51, 160, 74' -- RGB orange
else '0,0,0' -- RGB black for no data
  end

In the example, "field" is your field with the data that define the colour.

t

To have more than one font/icon in your label just add (clicking in the green +) a second font marker and repeat the colour operation (changing the "field" ad preferred). Correct the offset of the new symbol to avoid overlaps.

enter image description here

4
  • Very well done. Mar 10 '20 at 14:33
  • Thanks for your suggestion but it's not completely answering my needs as sometimes one filed will be empty, so using sumbology there will be a hole between symbols. That's why using labels would be the best solution. Building a concatenate expression between fields and then applying different colors to each field. I tried using your expression in the label color options but it doesn't work. It's seems it's not possible.
    – m_beeckman
    Mar 11 '20 at 8:33
  • I will try to work on it today. The expression should works with few arrangements.
    – Val P
    Mar 11 '20 at 8:57
  • If I got properly your request, you want to create a multilabel with a lot of variables, one for each field multiplied for all the possible attributes of each of them. Do you have already this expression? Because change the colour of the label is not a problem but you need to refer to the main expression.
    – Val P
    Mar 11 '20 at 20:20

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.