I want to remove all selection from registered layer in QGIS using Python. I tried to clear the map canvas using:
self.iface.mapCanvas().clear()
self.iface.mapCanvas().refresh()
but the selection persists.
Answer
There is probably a better way to do this, but you can iterate the layers in mapCanvas, and use removeSelection() method.
Something like this:
mc = self.iface.mapCanvas()
For layer in mc.layers():
if layer.type() == layer.VectorLayer:
layer.removeSelection()
mc.refresh()
No comments:
Post a Comment