I have a group of layers that contain itself other groups (as shown in picture).
I need to hide one group by uncheking the checkbox in the legend.
is there any way to do it programatically using python?
For QGIS 3.x, you can use:
treeLayer = QgsProject.instance().layerTreeRoot().findLayer(layer.id())
if treeLayer:
treeLayer .setItemVisibilityChecked(False)
QgsProject.instance().layerTreeRoot().findGroup(vignette_group_inter.name()).setVisible(0)
to set invisible :
QgsProject.instance().layerTreeRoot().findGroup(group_inter.name()).setVisible(0)
to set visibe :
QgsProject.instance().layerTreeRoot().findGroup(group_inter.name()).setVisible(2)
because
Qt::Unchecked 0
Qt::PartiallyChecked 1 (some children are checked and some are not)
Qt::Checked 2