Bug report #14153
loadNamedStyle fail to load edit widget
|Affected QGIS version:||master||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:||end of life|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||22155|
This code correctly loads style from qml file and adds layer 'test' to the map canvas (see attached zip file).
The QML file defines edit widget for attribute called 'attr' with the 'value map' type (see attached screenshot):
vl = QgsVectorLayer('test.shp', 'test', 'ogr') QgsMapLayerRegistry.instance().addMapLayer(vl) vl.loadNamedStyle('style.qml')
But this code doesn't load correct edit widget, just shows default 'Text Edit' edit widget
vl = QgsVectorLayer('test.shp', 'test', 'ogr') vl.loadNamedStyle('style.qml') QgsMapLayerRegistry.instance().addMapLayer(vl)
Note: both codes correctly load renderer style
#1 Updated by Sebastian Dietrich over 4 years ago
- Affected QGIS version changed from 2.10.1 to master
Widgets are loaded separately from the layers by
QgsEditorWidgetRegistry. It watches the layers that are known to it and when a layer is loading a new style,
QgsEditorWidgetRegistry loads the widgets for that layer.
QgsEditorWidgetRegistry only knows of the layers that are added to
QgsMapLayerRegistry. So the effect is as you describe: loading QML after adding the layer works, loading QML before adding the layer does not.
The solution could be to simply make all (vector-)layers known to
QgsEditorWidgetRegistry. But that might have other, probably unwanted, effects. I can't tell.
#3 Updated by Giovanni Manghi over 1 year ago
- Resolution set to end of life
- Status changed from Open to Closed
End of life notice: QGIS 2.18 LTR