4

I need to update a vector layer's data when the visibility is turned back on. My update does not occur when the visibility is off.

To what signal do I need to connect to catch the visibility change?

4

An example to complete @snaileaters's anwser :

def print_informations(layerTreeNode, checkstate):
'''print some informations when a group or a layer is checked'''
    if checkstate:
        if layerTreeNode.nodeType() == 0:
            print "Group " + layerTreeNode.name()
        else:
            if layerTreeNode.nodeType() == 1:
                print "Layer " + layerTreeNode.layerName()
            else:
                print "Error"

root = QgsProject.instance().layerTreeRoot()
root.visibilityChanged.connect(print_informations)
| improve this answer | |
2

the visibilityChanged signal of a QgsLayerTreeNode object should do the job i think.

| improve this answer | |
  • My answer only applies when checking/unchecking group/layer in the Layer Tree view not when layers appear/disappear due to a scale based visibility setting ... – snaileater Jul 2 '15 at 11:41
  • This may help. How do I get the TreeNode from the layer? – Worth Lutz Aug 18 '15 at 18:27

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.