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?


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()
            if layerTreeNode.nodeType() == 1:
                print "Layer " + layerTreeNode.layerName()
                print "Error"

root = QgsProject.instance().layerTreeRoot()

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

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • 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.