0

I update a feature in a vector layer using the following Python code:

layers = QgsMapLayerRegistry.instance().mapLayers()     
layer = layers.get('my_vector20140614125509945')

fid = 1
attrs = { 0 : "hello", 1 : 100 }
layer.dataProvider().changeAttributeValues({ fid : attrs })

The feature is updated but the map is not redrawn. I am using catagorized style. The value of 100 will be shown with a different color.

1 Answer 1

1

Just need to tell the canvas to refresh.

iface.mapCanvas().refresh()
2
  • I tried to get the canvas by canvas = qgis.gui.QgsMapCanvas() and call canvas.refresh() But the map is not repainted. But after I clicked the map, it is repainted.
    – wannik
    Jun 15, 2014 at 3:29
  • 1
    Thank you very much. iface.mapCanvas().refresh() works.
    – wannik
    Jun 15, 2014 at 4:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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