Sunday 22 May 2016

pyqgis - Binding value from QComboBox in QGIS custom Form?


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?



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

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...