I've got several rule-based layers in my project (qgis 2.18.13). Is it possible to check/uncheck the visibility of all rules (not the visibility of the layer itself) at once? If yes - is it possible to do this on all layers of the project at once too?

  • Doesn't seem like it. It would be nice and intuitive if selecting all of the rules and then clicking any of the checkboxes toggled all of the selected ones.
    – Iamlukesky
    Nov 8, 2017 at 12:38

1 Answer 1


You could use something like the following to check or uncheck all rule-based style categories from all layers loaded in your project:

from PyQt4.QtCore import Qt

for layer in QgsMapLayerRegistry.instance().mapLayers().values():
    renderer  = layer.rendererV2()
    if renderer.type() == 'RuleRenderer':
        ltl = QgsProject.instance().layerTreeRoot().findLayer(layer.id())
        ltm = iface.layerTreeView().model()
        legendNodes = ltm.layerLegendNodes(ltl)
        for ln in legendNodes:
            ln.setData(Qt.Unchecked, Qt.CheckStateRole)
            #ln.setData(Qt.Checked, Qt.CheckStateRole)

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.