1

I am trying to define the font for features based on values in the attribute table. This is what I have tried in the Expression String Builder next to the Font dropdown in Layer Properties/Labels/Text:

CASE
WHEN  "descriptio"  =  'LABAYKU'  THEN Arial ELSE Times_New_Roman
END

The Expression Builder doesn't report an error, but returns Null and the font of the labels doesn't change. I tried putting brackets around the name of the font but that results in an error. I have been able to define the font size using an expression, but haven't been able to find an example of an expression that lets you customize the font itself. What would be a valid expression?

5

The font names need to be quoted.
Also Times New Roman needs spaces not underscores (tested in QGIS 2.18.14).

Try this:

CASE
    WHEN  "descriptio"  =  'LABAYKU'  THEN 'Arial' ELSE 'Times New Roman'
END

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.