3

I want to know if there is signals in layers tree to get notified when the active layer changed or more precisely when the user clicks or dbl click on any layer or node in the layers tree view.

I search in QGIS documentation but found nothing!

7

I have the solution after playing around here in the related questions to my question:

def test(lyr):
    print(lyr.id())


iface.legendInterface().currentLayerChanged.connect(test)

the sample code above is not perfect but showing the solution, the signal currentLayerChanged fires every time the user changes the selected node or item (layer) in the layers treeview.

2

In QGIS3

def test(lyr):
    print(lyr.id())

iface.layerTreeView().currentLayerChanged.connect(test)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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