[QGIS-Developer] loadNamedStyle() is loading default style instead of QML file

Alexandre Neto senhor.neto at gmail.com
Mon Sep 11 04:33:10 PDT 2023


I am trying to load a style from a QML file into a vector layer.

When I use a memory layer, loading the style works fine with the following code:

layer = iface.activeLayer()
layer.loadNamedStyle(path_to_style)

If the layer is a postgreSQL layer with a default style, the above code will return:

('Loaded from provider', True)

and the style from the QML won't be loaded. The way to force it was add a True parameter in the end of the method call:

layer = iface.activeLayer()
layer.loadNamedStyle(path_to_style, True)

Not sure if this is the correct behavior, but it does not match with the documentation:

https://api.qgis.org/api/classQgsMapLayer.html#a8b271b8bf3074e84808cff26f722b26f <https://api.qgis.org/api/classQgsMapLayer.html#a8b271b8bf3074e84808cff26f722b26f>

Thanks,

Alexandre Neto
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230911/8d5154ef/attachment.htm>


More information about the QGIS-Developer mailing list