I am trying to build a custom form for field data collection (bird species) with some python logic. The python code inserts values into a QComboBox:
- At the beginning of the list it adds the twenty most often used species
- then follows a separator
- then a complete list of possible species
After finding Custom QGIS feature forms – Value Binding I learned, that I have to set the correct widget type in the "Fields" tab of the layer properties dialog.
Now QLineEdits (Edit Widget -> "Text Edit") and QSpinBoxes (Edit Widget -> "Range") work as intended. But I can't find a widget type that correctly binds the values of my QComboBoxes.
Which type of "Edit Widget" do I have to choose to bind a QComboBox from a Qt custom form?
Answer
It seems to me, that there is no way to correctly bind a QComboBox. Looks like a bug to me.
I solved the problem by creating a QLineEdit, that is bound to the attribute (set edit widget to "Text Edit"), and hiding this LineEdit behind a ComcoBox. Every change of the value in the ComboBox triggers a function, that sets the text of the LineEdit to the current Text of the ComboBox.
Not elegant, but it works.
No comments:
Post a Comment