I am struggling to alter the label colours according to field values (as strings) in the attributes table.

In my mind what I want is:

If the string in column X = 'Proposed' Then label the point using the string in column Y, with color A

Else Label the point using the string in column Y, with color B End

I have tried a bit, but struggling with the syntax

case when  "ownerenc" = 'Proposed' 
then  (color_rgb(256,256,256))
else  color_rgb(56,56,0)   

But I realise this is quite wrong! Many thanks for your suggestions.

  • Does someone have an idea to color only a part of the label according a value, like this: ![enter image description here](i.stack.imgur.com/B5jOa.png) The (nice) answer from Alexander is only concerning the whole label. Thanks for your help!
    – Luc
    Feb 6, 2018 at 17:15
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – JGH
    Feb 6, 2018 at 19:15
  • This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review
    – Hornbydd
    Feb 6, 2018 at 19:45

1 Answer 1


The syntax is almost correct (see the note in the end), but you might be using it in the wrong place.

The correct way of doing it is like this.

  1. Label your layer using your "Column Y" field, in the example below that's field "codigo".
  2. go to the "text" sub-menu, color and click the data defined button;
  3. There choose the edit... option below Expression;

enter image description here

  1. Put the desired expression in the expression builder (in the example).

enter image description here

Note: The rgb() function will only accept values from 0 to 255 to the red, green and blue arguments.

  • 1
    I wanted to! But I couldn't find anywhere where to do this. Now I looked again and I have seen the green tick. Thanks
    – dreab
    Sep 3, 2014 at 14:55

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.