2

I have a problem with the background color in a label in print layout in QGIS. I would like to set the color of the label to be dependent on the data from the attribute table.

For example, when column A=1 the background will be yellow. When column A=1, green etc.

  • Welcome to gis.stackexchange! Please note that a good question on this site is expected to show some degree of research on your part, i.e. what you have tried and - if applicable - code so far. For more info, you can check our faq. – underdark Feb 2 '18 at 20:19
2

You can set an expression to control the colour of the "halo" of your text label.

enter image description here

Once you've clicked that button chose edit and then you can add any expression you like, something like this should work:

CASE 
  WHEN   "objectid" = 1 THEN color_rgb( 0,0,0) 
  WHEN   "objectid" = 2 THEN color_rgb( 10,0,0)
 END
  • If you want to match the background color to the symbol color you could use @symbol_color expression – J.R Feb 2 '18 at 10:31
  • I think the OP wants a different colour to the background, otherwise why bother with a halo – Ian Turton Feb 2 '18 at 10:32
  • 1
    Ok, but it's about label in print layout (in text field). When I add a text fiel, I would like the background color to change depending on the attribute table. In option "background" there is not choince "extension". – Michal DML Feb 2 '18 at 10:45
  • 1
    I'm not sure if that could work, the text field doesn't know which feature you want to consider. – Ian Turton Feb 2 '18 at 10:47

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.