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?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
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)
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.