I have a python script, which imports a GeoPackage File into my project at a specific place (inside a group).
After importing the GeoPackage I load a QML-Style-File into it, all via Python.
Works like a charm at first sight. Everything is displayed correctly. I noticed a weird Bug in the Export to PDF via the Layout Manager though: My Export has a grey background with only certain lines. It seems that all styles are missing (see screenshot).
Additionally: When I try to drag and drop the layer in the panel, all styles are lost (see GIF).
That does not happen, when I load the styles onto the Layer manually. Then the PDF Export is also fine. It seems that the loading of the QML via Python does some damage.
EDIT: I narrowed it further down. The Error persists when loading the style manually onto the python-loaded Geopackage Layer. When importing the Layer manually it works: I can manually load the style and reorder it without any problems. So the import of the GeoPackage Layer must be somehow the problem.
I'm on MacOS, QGIS 3.34 Conda.
Here's the code excerpt which loads the style file:
def load_qml_style(layer, qml_file):
layer.loadNamedStyle(qml_file_path)
layer.triggerRepaint()
# Load QML style file onto GeoPackage layer
if os.path.exists(qml_file_path):
load_qml_style(gpkg_layer, qml_file_path)
else:
print("QML style file not found:", qml_file_path)
# Refresh the Layers Panel
iface.layerTreeView().refreshLayerSymbology(gpkg_layer.id())