11

Is it possible to label a layer using same colors as the categorized symbology of that layer?

It is possible using the Rule-based labeling, but it can be difficult for a layer with many categories and maybe it can be done using the Data-defined override, but I don't know how to get the color used for every category.

1

2 Answers 2

18

Using QGIS 3.4.5, you can write @symbol_color in the data defined override for coloring the text:

  1. Go to Data defined override -> Edit

enter image description here

  1. Write the following:

@symbol_color

enter image description here

  1. Use buffer around the text to see the label
  2. Output:

enter image description here

For multi-layer symbol, note that @symbol_color returns the color of the last symbol layer (the one on the bottom, be it visible or not) ex of multi-layr symbol

0

I can report that this feature does not work if the labeled layer uses geometry generators – the color reverts to black. Seems to be a bug. symbol color reverts to black on layer with geometry generator

There is a workaround for this (put a standard symbol in, disable visibility, move it to the bottom of the symbology list - @symbol_color will always pick up the colour of the bottom-most symbol.)

4
  • 4
    If you discover a bug, please report it directly on github.com/qgis/QGIS/issues
    – MrXsquared
    Apr 30, 2020 at 15:52
  • 4
    Please raise this as a separate issue or comment. Your answer will likely be deleted but i have a workaround for this (put a standard symbol in, disable visibility, move it to the bottom of the symbology list - @symbol_color will always pick up the colour of the bottom-most symbol.)
    – she_weeds
    May 1, 2020 at 11:57
  • Nice trick @she_weeds, i confirm your workaround does the job ...
    – Snaileater
    May 18, 2020 at 14:21
  • @she_weeds, thank you for the trick, it saves my day.
    – kFly
    May 7, 2022 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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