J
J
jkrieger2014-05-11 12:46:41
Qt
jkrieger, 2014-05-11 12:46:41

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")
widgetmapper-combo-mapping.png
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

2 answer(s)
O
Oleg Utkin, 2014-05-20
@senatus

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");

J
jkrieger, 2014-05-22
@jkrieger

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))

Doesn't work: mapper doesn't set values.
At the moment, I have implemented my QItemDelegate, in which I have overridden setEditorData and setModelData. And I got a non-Editable QComboBox working. With Editable it's worse - you can't select a value from the list. But I suspect the problem is elsewhere.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question