3

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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jun 27, 2019 at 16:36

1 Answer 1

5

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

answered Jun 27, 2019 at 16:58
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. Commented Jun 28, 2019 at 14:15
  • Ah okey!Update my answer 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) Commented Jul 1, 2019 at 12:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.