How to get dependable refresh on mapcanvas in Python?

How to get dependable refresh on mapcanvas in Python?

With canvas caching in the mix ( python cookbook, note at the end of the ‘Modifying Vector Layers’ section ), I have to do the following to get a dependable refresh after an edit (in my case from within plugin code in QGIS 2.14): That is, I always call triggerRepaint () on all layers and then call the mapCanvas’s refresh () just to be safe.

How to set layer visibility in QGIS 3?

For QGIS 3, you have to use: QgsProject.instance ().layerTreeRoot ().findLayer (layer_id).setItemVisibilityChecked (False) Reading the documentation, findLayer accepts both the layer itself or the layer ID as a string. After this the map Canvas will redraw and you can see the changes.

How to see changes in a layer in findlayer?

Reading the documentation, findLayer accepts both the layer itself or the layer ID as a string. After this the map Canvas will redraw and you can see the changes. Normally you should see changes when you zoom in and out to force a refresh of the mapCanvas manually.

Why does refresh not work in QGIS 2.6?

The API warns that both QgsMapLayer.setCacheImage () and QgsMapLayer.clearCacheImage () are deprecated, but nothing in the documentation or code mentions what alternative is planned. Side note: I’m still seeing a refresh bug.

Is it possible to reopen a file before QGIS 2.10?

Before QGIS 2.10, a file was reopened on every single access (e.g. repaint). Since QGIS 2.10 the file handle is kept open and this means if a file is replaced the handle still points to the old file on Unix based systems. Unfortunately there is no API to nicely force QGIS to reopen the file in QGIS 2.10. As a workaround you can use an ugly hack:

How to make QGIS layer update from changed data source?

Or maybe I did something two minutes ago. The one reproducible way of getting it to update is to duplicate the layer from the legend menu – the duplicate always gets its data from the current shapefile, and the original layer updates itself too! So there must be some way of doing it.