[PyQt] Synchronization of QDataWidgetMapper index of new row with respect to QSqlTableModel sort criteria

bar tomas bartomas at gmail.com
Mon Jul 12 12:03:35 BST 2010


Hi,

I'm using a QDataWidgetMapper to map the fields in a database table to
the fields in a form.
The QSqlRelationalTableModel model associated to my QDataWidgetMapper
has a sort criteria on the basis of an integer field.
My problem is how to set the correct index of the QDataWidgetMapper
when a new record has been submitted.

Before submitting the new record, I have tried memorizing the current
index of the row created with the currentIndex() method  of the
QDataWidgetMapper. However this does not give the correct index
because it does not take into account the sort criteria of the
QSqlRelationalTableModel  (I guess that what happens is that when a
new row is created, it's index is the number of rows in the model +1.
However after it is submitted, the sorting criteria aplies and its
position in the row set changes ?)

How can I retrieve the correct index of the row of a newly created
record QDataWidgetMapper, that takes into account the sort criteria of
the corresonding model?

Many thanks.


More information about the PyQt mailing list