[GIS] Changing the label color with the Expression Dialog in QGIS 3.4.1

labelingqgis

I want to separate two labels and then coloring each one separately, using QGIS 3.4.1.
So, I was trying to color a label within the Expression Dialog.
However, I could not figure out how to wright the function.

enter image description here

I tried all the Color function, but it did not worked.
The color's name was taken from the "Select Text Color" within the "layer Styling" bar and it a shade of green that supposed to replace the red.

enter image description here

Best Answer

You can set a label color using expressions, but not in the label value field. You need to use the datadefined override for the color selector.

Example:

if( "Attribute_name" = 'value', '#FF0000', '#000000')

The above expression sets the color to red if true and black if false.

To help you build your expression you can also use the "Assistant..." when clicking on the datadefined override button to the right of the color selector.

Related Question