5

I want to access the name of a rule in the rule-based labeling of a layer in QGIS via Python.

Getting all the attributes works for me, also the preview text. But I didn't find the property to get the name of a rule. Here a short code example:

layer = iface.activeLayer()
labeling = layer.labeling()
    
for rule in labeling.subProviders():
    print(labeling.settings(rule).Show)
    print(labeling.settings(rule).Priority)

1 Answer 1

10

You have to use description method of class QgsRuleBasedLabeling.Rule.

layer = iface.activeLayer()
labeling = layer.labeling()

for rule in labeling.rootRule().children():
    print(rule.description())

enter image description here

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.