0

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?

enter image description here

0

For QGIS 3.x, you can use:

treeLayer = QgsProject.instance().layerTreeRoot().findLayer(layer.id())
if treeLayer:
  treeLayer .setItemVisibilityChecked(False)
|improve this answer|||||
  • Iam working with QGIS 2.x , so I used this : QgsProject.instance().layerTreeRoot().findGroup(vignette_group_inter.name()).setVisible(0) – Namoat Dec 5 '19 at 10:56
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
|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.