[PyQt] QDataWidgetMapper

Sibylle Koczian Sibylle.Koczian at t-online.de
Sun Dec 2 11:00:16 GMT 2007


Hello, Daniel,

Am Montag, 26. November 2007 13:59:52 schrieb Daniel Lundqvist:
> Hey,
>
> I've been struggling to get the above to work correctly. I've looked
> around but haven't found a solution to my problem yet.
>
> The issue I'm having is I can't get the mapper to update the widgets at
> all. Not even when I call setCurrentIndex(n).
>
> I'm attaching my sample project that shows the problem. The sample
> contains a simple model with two columns. One combo box show column 0
> from the model and a QLineEdit should show second column from the index
> selected in the combo box. (I've also tried connecting
> QComboBox::activated(int) -> QDataWidgetMapper::setCurrentIndex(int) to
> no avail).
>

Did you solve your problem? I've tried several variations, but the only one 
that did help was putting your data into a QStandardItemModel.

Things I tried:
- subclassing QAbstractTableModel instead of QAbstractItemModel, because your 
model isn't hierarchical
- storing the data directly in the model
- making column 1 of the model editable
- setting the model row in the __init__ method either with .toFirst() or 
with .setCurrentIndex(self.ui.comboBox.currentIndex())

In another variation I put an additional QTableView into the main window. This 
shows all the data correctly and can easily be synchronized with the 
combobox. But still the QLineEdit is empty.

In the meantime I got my copy of the PyQt book, but it uses the 
QDataWidgetMapper only with data from a database, not with a custom model.

What does the QDataWidgetMapper expect from a model?

Sibylle



More information about the PyQt mailing list