1

I would like to have two types of text in my layer.

I have one value in the data attribute table, which is "Timestamp" and its value is 0 or 1. 1 for bigger and black font, 0 for the smaller and grey font. The value I want to be displayed is "description".

I tried several approaches, which are here:

Single text label in dual font size in QGIS

How to create a label combining different font sizes or types?

Single text label in dual font size in QGIS

and finally, I used this one:

Setting different font color types from the same field in rule-based labeling in QGIS

which works fine when considered the cont color only.

enter image description here

I tried to set up two separate conditions based on the same columns in the data attribute table (timestamp for font condition and description for value displayed).

enter image description here

but it didn't work as expected.

Finally, I tried the formula:

  CASE WHEN "Timestamp" = 1 THEN
  '000000' AND 12 
   ELSE
   '808080' AND 7
   END

and text partially disappears.

What problem can be here?

6
  • 1
    Why don't you use data defined override?
    – Erik
    Commented Feb 25, 2022 at 11:43
  • I don't know about this option
    – Geographos
    Commented Feb 25, 2022 at 11:44
  • 1
    docs.qgis.org/3.16/en/docs/user_manual/introduction/… - you may base a lot of settings in the symbology on attributes of the layer. Either simply set a field which holds a corresponding value, or enter a valid expression. E.g. CASE WHEN "Timestamp" = 1 THEN 10 ELSE 5 END for the font size.
    – Erik
    Commented Feb 25, 2022 at 11:47
  • 1
    Then set the according expression as data defined override for the colour.
    – Erik
    Commented Feb 25, 2022 at 11:55
  • 1
    What are you intending with the AND's in your CASE statement? AND is a conditional operator and is likely a syntax error how you are using them. If you want to concatenate, you can use ||
    – Matt
    Commented Feb 25, 2022 at 13:07

1 Answer 1

2
+50

You are misusing the rule based labeling.

The formula in the "rule" setting is used to select witch object are labelled, not how they will be labelled. So your two rule should be :

Description : Timestamp value is 1 : bigger and black font - Rule : "Timestamp" = 1

Description : Timestamp value is 0 : smaller and grey font - Rule : "Timestamp" = 0

(It could be advisable to set a third "ELSE" rule if you can't guarantee that the timestamp will always be filled with either 0 or 1)

Then you set how each rule are labeled the exact same way you would while using single labels . Each rule are totally independent on how they are labelled and can use any setting regardless on setting on other rules. It's the same as if you where labeling two different layer.

enter image description here

enter image description here

enter image description here

If you want to use data defined override you should select single label, set all labeling option the usual way except for the font size and font color where you should select the edit option by clicking on the symbol next right to the font and symbol selector and use an expression to set the relevant setting (for font size you may use the CASE WHEN "Timestamp" = 1 THEN 10 ELSE 5 END expression suggested by @Erik)

enter image description here

Note that when using data defined override you need to input an expression for each setting you want to individualise while rule labeling require that you create a rule for each kind of label you need.

So as a rule of thumb : for creating a few distinct label type (as in your case two distinct label) it's better to use rule labeling. While if you want to get lot of similar label (like a label colored accordingly to a field value) it's better to use data defined override. Of course for overly complex labeling you may mix the two approach....

Your Answer

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

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