I have a quite complex rule-based symbology that is currently using millimetres as size units.

rule-based symbology

All third levels look the same, they just have different parents.

Is there a way to change symbol size units from millimetres to map units for every rule entry so I don't have to click each entry and switch (which would be a pain in the * for a few dozen entries)?

When I have a categorized approach, I have the general symbology, that I can easily change and then applies to all categories, but how do I achieve that with a rule-based symbology?

The same goes for other aspects, like symbol size. Can I change that size for all symbols at once? e. g. from 15 mu to 18 mu.


2 Answers 2


Use the following script in QGIS Code Editor. It also works on nested rules. Select the layer before running the script.

layer = iface.activeLayer()
renderer = layer.renderer().clone()

def set_output_unit(rules):
    for rule in rules.children():
        rule.symbol().setOutputUnit(1) # 1: MapUnits    
        if rule.children():

rules = renderer.rootRule()


enter image description here

  • I am on my rulebased layer. could it have anything to do with nested styles and the parents not having any symbology on their own?
    – e-shirt
    Commented Mar 6, 2023 at 11:30
  • It could be. Could you share a screenshot on how the rule-based symbology looks like? Commented Mar 6, 2023 at 11:52
  • I added a picture. As you can see, two symbols I have manually changed to map units, the others didn't
    – e-shirt
    Commented Mar 6, 2023 at 12:26
  • Ok. I've edited the answer. Now, it works on nested rules. Commented Mar 7, 2023 at 20:18

Quick and dirty would be:

  • export Style as *.qml
  • open it in Notepad++ for example
  • search for: <Option value="MM" type="QString" name="line_width_unit"/>
  • replace with: <Option value="MapUnit" type="QString" name="line_width_unit"/>
  • import your style again

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.