pyqgis get all checkboxes site:gis.stackexchange.com
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)