4

How can I change the colour of text labels by category? EG, I have a text layer with text that is categorised into 6 different categories. I need either the text itself, or its background to match the colour of polygons that are also in that category. I've hunted through here but can't find any answers that I can understand. It looks like the way forward involves some kind of rule based style, but I can't make head nor tail of the info I've found If I was using our old method, I would have text boxes with black text, a background that was a lighter shade of the colour used for the category, and an outline to the text box in a darker shade of that colour. Is there a way to do something similar here? I've added some screenies. With the text all the same colour and the background all the same colour, it's difficult to see which label belongs to which object.

the categories for polygons

the map

the labels

6

Very straightforward.

You simply need to define a data driven override for the colour:

enter image description here

Then double click on symbol_color. The expression will be:

@symbol_color

enter image description here

Result:

enter image description here

Works on any colour that you want to change. To lighten it up, you could add a bit of transparency.

  • Thanks but data defined over-ride is greyed out. I can't select it. – PJ Lightning Jan 17 '18 at 15:57
  • OK. I clicked on edit which gave me that box and I double clicked on symbol color. The backgrounds now have colours but they are the wrong colours. I can't see a way to edit them. – PJ Lightning Jan 17 '18 at 16:00
  • 1
    It will be the same colour as the fill colour of the symbol. – HeikkiVesanto Jan 17 '18 at 16:09
  • I don't want the symbols to show. They make it look like the label applies to the point when it actually applies to the polygon. I also have point features in the map and this would be very confusing for clients. Ah. After some fiddling, I found that I can set an invisible font marker with the right colours and that lets me control the background without adding a symbol. Thank you. Sorted. :) – PJ Lightning Jan 17 '18 at 16:17
  • 1
    @PJLightning If this answer resolved your problem, please Accept it (check mark below the up/down vote buttons). You may wish to review your other questions and see if you can accept an answer on those as well. – jpmc26 Jan 17 '18 at 20:16

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.