How could I use layer.setEditType() method in QGIS for a custom form widget? Cusom form elements are well explained by Matthias Kuhn here.
I was able to change the existing default widget types. For instance, layer.setEditType(idx, layer.ValueMap)
but when I tried the same on a custom widget, it doesn't work. How could I do it?
Answer
The method setEditType
is really old and no longer recommended (and will disappear with QGIS 3.0).
If you have a look at the API documentation, it redirects to the appropriate successor: https://qgis.org/api/classQgsVectorLayer.html#a2d1e5058f8b7cc5c905813485847bc81
layer.editFormConfig().setWidgetType(idx, "ValueMap")
or
layer.editFormConfig().setWidgetType(idx, "YourCustomWidgetId")
Closely related is also the method setWidgetConfig
layer.editFormConfig().setWidgetConfig(idx, { 'rule': '[A-Z].*' })
No comments:
Post a Comment