[PyQt] QDataWidgetMapper

Daniel Lundqvist daniel.lundqvist at packetfront.com
Mon Dec 3 07:45:43 GMT 2007


On Sun, 2007-12-02 at 12:00 +0100, Sibylle Koczian wrote:
> 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.

Yes, sorry for not getting back here. The main error was in data(). It
did not correctly return data when role was EditRole (which is what
QDataWidgetMapper asks for).

> Things I tried:
> - subclassing QAbstractTableModel instead of QAbstractItemModel, because your 
> model isn't hierarchical

Yeah, I guess this makes more sense. Some of the functions in my model
can be eliminated then.

> - making column 1 of the model editable

Did you do that by returning ItemIsEditable from flags()?

> What does the QDataWidgetMapper expect from a model?

Nothing more than it being correct :)

I used the modeltest.py from contrib to fix some things in my model (but
it had no way of detecting my error in data()).

Thanks for looking into this. Attaching a corrected model.

-- 
daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mymodel.py
Type: text/x-python
Size: 1463 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20071203/2f75a2d5/mymodel.py


More information about the PyQt mailing list