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.

1
  • 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
    Commented Feb 2, 2018 at 20:19

1 Answer 1

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
4
  • If you want to match the background color to the symbol color you could use @symbol_color expression
    – J.R
    Commented Feb 2, 2018 at 10:31
  • I think the OP wants a different colour to the background, otherwise why bother with a halo
    – Ian Turton
    Commented Feb 2, 2018 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
    Commented Feb 2, 2018 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
    Commented Feb 2, 2018 at 10:47

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