1

I have a layer with a style that I save

enter image description here

layer = iface.activeLayer()
layer.saveNamedStyle('F:/test.qml')

I modify the style of the layer

enter image description here

I want to run a script to apply a qml style to a layer.

layer.loadNamedStyle('F:/test.qml')
iface.mapCanvas().refresh()
iface.legendInterface().refreshLayerSymbology(layer)

my line of code works if I modify the zoom level with the mouse wheel.

Why isn't refreshing done alone?

enter image description here enter image description here

1 Answer 1

3

Probably the call you are missing is layer.triggerRepaint()

Try:

style_path = r'Path\to\style_file.qml'

lyr = iface.activeLayer()

lyr.loadNamedStyle(style_path)

lyr.triggerRepaint()

# update legend symbology (shouldn't be needed)
iface.layerTreeView().refreshLayerSymbology(lyr.id())
0

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.