I am saving my layer-styles in the same spatialite-database, where the layer-data is saved and I am able to load the layer (with the default style) to the canvas (using PyQGIS in a plugin).
But how do I load an alternative style for this layer from my spatialite-database (from the table 'layer_styles')?
I have found the method
loadNamedStyleFromDatabase(self, db: str, uri: str), but I have troubles to set the parameters.
db is like
G:/path/to/database.db. But how to set the parameter
uri correct to load an alternative layer-style.
Or is there an other way to do this. E.g. I can get the qml- or sld-definition from the table 'layer_styles' for the wanted layer. But how to load the layer with this definitions?
EDIT on 16.05.2019:
I have now tried to load the style with
importNamedStyle like this:
layer = QgsVectorLayer(uri, base_name, provider) style_qml = layer.getStyleFromDatabase(str(style_id)) style_doc = QDomDocument("qgis") style_doc.setContent(str(style_qml)) layer.importNamedStyle(style_doc) QgsProject.instance().addMapLayer(layer) self.canvas.refresh()
I get the values for
style_id from the database and I have controlled them, they are right (incl.
I have e.g. two styles for one layer stored in the database. On running the code above, then only one of them is loading. No one of the two is set as the default style.
How can I load the style correct?