2

I have these groups of layers with their layers inside in QGIS:

Layers with groups of layers

I have an event in PyQGIS that notices when I select a layer like RODAL or MONTE:

iface.layerTreeView().currentLayerChanged.connect(self.eventoClickPanelCapas)

However, what I really want is to have an event that notices when I select a group of layers, for example, PT_P000052SA_N. I don't know if it is possible or not.

Taras
  • 32,823
  • 4
  • 66
  • 137

1 Answers1

6

You can use and modify this script:

from qgis.utils import iface
from qgis.core import QgsLayerTreeNode

view = iface.layerTreeView()

def eventoClickPanelCapas(): selected = view.selectedNodes() if len(selected)==1 and selected[0].nodeType()==QgsLayerTreeNode.NodeGroup: print("Group selected")

view.selectionModel().selectionChanged.connect(eventoClickPanelCapas)

enter image description here

Taras
  • 32,823
  • 4
  • 66
  • 137
Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389