I am trying to create a custom form for QGIS 2.0 with comboboxes containing an "other" category. I wonder how to provide a line edit to enter info replacing the "other" choice if chosen. Not sure if I can sync a combo box and a line edit at the same time under field properties.
In pseudo code:
myfield = dialog.findChild(QComboBox, "Myfieldname")
otherfield = dialog.findChild(QLineEdit, "Myfieldname")
if myfield.currentIndex() == -1:
set myfield to otherfield.text()
This thread's idea seems very similar, but I'm having trouble adapting it: How to automatically populate fields instantly?
my custom form code so far:
Naturefield = None
Nat_autrefield = None
def formOpen(dialog, layerid, featureid):
global myDialog
myDialog = dialog
global Naturefield, Nat_autrefield
Naturefield = dialog.findChild(QComboBox, "Nature")
Nat_autrefield = dialog.findChild(QLineEdit, "Nat_autre")
Naturefield.currentIndexChanged.connect(autreChanged)
def autreChanged(value):
#intending to take on form of line edit only if 'Autre' chosen
if Naturefield.currentText() == 'Autre':
Naturefield.setLineEdit(Nat_autrefield)
setLineEdit() currently transforms my combo box to make the list editable for all choices if 'autre' is chosen and the combo box stays a line edit once 'autre' is chosen--not exactly what i'm aiming for. Instead, I'd like the combo box to receive the input from a line edit only if 'autre' is chosen, and revert to normal combo box if other choices are chosen. This is all in the interest of data quality control.
I'm new to QtDesigner and Python.