I can set most font properties like this:

layer.setCustomProperty("labeling", "pal")
layer.setCustomProperty("labeling/enabled", "true")
layer.setCustomProperty("labeling/fontFamily", "Noto Sans")
layer.setCustomProperty("labeling/fontSize", "10")
layer.setCustomProperty("labeling/isExpression", True)
layer.setCustomProperty("labeling/fieldName", "title")    
layer.setCustomProperty("labeling/placement", "0")

But not font color. I've tried various ways of specifying the color:

layer.setCustomProperty("labeling/fontColor", "red")
layer.setCustomProperty("labeling/fontColor", "#ff0000")
layer.setCustomProperty("labeling/fontColor", QColor(255,0,0,255)

Surely there is a custom property for font color?


You need to specify the value for the red (R), green (G), blue (B) and alpha (A) parameters which are stored in the textColor property:

layer.setCustomProperty("labeling/textColorR", 255)
layer.setCustomProperty("labeling/textColorG", 0)
layer.setCustomProperty("labeling/textColorB", 0)
layer.setCustomProperty("labeling/textColorA", 255)

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.