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

2 Answers 2

0

For QGIS 3.x, you can use:

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

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