When loading a QGIS-project using a Python-file and having the same name on both shp- and qml-file, just the symbology and labels are according to the style-file, but not the widgets.

I have tried 2 methods:

  1. Use load.py to load a QGIS-project and add 1457_skrot.shp. 1457_skrot.qml is stored in the same folder as 1457_skrot.shp.

    python load_proj.py C:\kmfelt\shape\utm32\2017\1457_skrot.shp

  2. Use test_style.py to load a QGIS-project and to add both the shp-file and the qml-file in the py-file.

    python test_style.py

Code within the test_style.py:

vfile = r"C:\\kmfelt\\shape\\utm32\\2017\\1457_skrot.shp"
vlayer_name = os.path.split(vfile)[1]
print vfile
print vlayer_name
vlayer = QgsVectorLayer(vfile, vlayer_name, "ogr")
if not vlayer.isValid():
    print "Vector layer "+vlayer+" failed to load!"
QgsMapLayerRegistry.instance().addMapLayers([vlayer], True)

In both cases just the symbols (color, size) and labels are set according to the style-file. However, all the widgets are set to Text edit and NOT to the specific widgets set in the style-file. enter image description here

But, if I load the style-file manually (click Style - Load Style), the widgets change: enter image description here

Is it possible to achieve the same effect (including change in widgets) using Python? (I'm using QGIS 2.18.6.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.