Answer the question
In order to leave comments, you need to log in
How to modify Combo Widget Mapper to link by value rather than by index?
I ran into a problem similar to the one described in the QT docs:
qt-project.org/doc/qt-4.8/itemviews-combowidgetmap...
I also have two unrelated models. One of which contains a list of available options and should be bound in a QComboBox. The difference from the example is that in my first model, not the index is stored, but the value itself (if you look at the picture, then for "Carol" not "2", but "Other")
Please tell me how to make this example work in my case.
Answer the question
In order to leave comments, you need to log in
The combobox example uses the mapping of the currentIntex property :
Pay attention to the third parameter of the addMapping method .
You also need to link by text. For a combobox, the current text is set by the currentText property . Therefore, we replace only the name of the property when binding:
mapper->addMapping(typeComboBox, 2, "currentText");
I tried this way (I have PyQT):
if isinstance(pyqt_widget, QtGui.QComboBox):
self.data.mapper.addMapping(pyqt_widget, attrs.index(attr), 'currentText')
else:
self.data.mapper.addMapping(pyqt_widget, attrs.index(attr))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question