First of all, I have exported a layer style from a layer as a QML file including draw effects (symbology --> layer rendering --> draw effects) in symbology. Note that, I have checked all the categories while saving it (see below image).
Then, I have changed the values in the field which I have configured a Graduated Symbology with. Then I tried to load the QML file with loadNamedStyle()
. It did not change the legend and classes automatically. Therefore, I have tried a few things to automatically update that.
field = 'SPREAD'
stylepath = '/path_to_my_layer_style.qml'
layer = iface.activeLayer()
layer.loadNamedStyle(stylePath)
renderer = layer.renderer()
sym = renderer.sourceSymbol()
grad = renderer.sourceColorRamp()
renderVal = renderer.createRenderer(layer,field,5,0,sym,grad)
layer.setRenderer(renderer)
It worked. However, the effects in that QML file has disappeared after that. I also do not think this is the best way to do that. Is there a more convenient way to classify the symbology with new values after loading QML file in PYQGIS?