2

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

4

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()

3
  • 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
    Commented Jun 28, 2019 at 14:15
  • Ah okey!Update my answer
    – Fran Raga
    Commented Jun 28, 2019 at 15:59
  • 1
    Perfect! 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
    Commented Jul 1, 2019 at 12:11

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.