4

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:

  1. At the beginning of the list it adds the twenty most often used species
  2. then follows a separator
  3. 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?

2

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.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.