I am trying to use the python console to achieve the following manual procedure of setting each layer to refresh automatically at a specified time interval.
The manual process: Layer Properties> Rendering> [tick box] Refresh layer at interval (seconds)> [enter seconds].
How do I do this from the python console?
This specific rendering information is not stored in a style, and manually setting it for each new layer is time consuming. I often reload all of my layers into a new QGIS project, so being able to set the refresh interval rate with python will save a lot of time.
1 Answer 1
For set this property you need to change its value in the QGIS settings
from qgis.PyQt.QtCore import QSettings
QSettings().setValue("/qgis/map_update_interval", 150)
For set Refresh layer at interval (seconds) using PyQgis you need:
# Get layer by name
layer = QgsProject.instance().mapLayersByName('pipelines')[0]
# Enabled auto refresh
layer.setAutoRefreshEnabled(True)
# Set seconds (5 seconds)
layer.setAutoRefreshInterval(5000)
API reference setAutoRefreshInterval()
-
Thanks for your post. Unfortunately this isn't what i was after. I want to update the refresh interval rate for the layer, not the map update interval. If you follow the path mentioned above: Layer Properties > Rendering > [tick box] Refresh layer at interval (seconds) > [enter seconds]. It is this that i am trying to set from the python console.Demus– Demus2019年06月28日 14:15:23 +00:00Commented Jun 28, 2019 at 14:15
-
Ah okey!Update my answerFran Raga– Fran Raga2019年06月28日 15:59:47 +00:00Commented Jun 28, 2019 at 15:59
-
1Perfect! Thank you very much. Something worth noting: I found that the setAutoRefreshEnabled(True) only worked after an existing value was assigned to it from the setAutoRefreshInterval. Therefore I switched the order around: 1st layer.setAutoRefreshInterval(5000) 2nd layer.setAutoRefreshEnabled(True)Demus– Demus2019年07月01日 12:11:48 +00:00Commented Jul 1, 2019 at 12:11
Explore related questions
See similar questions with these tags.