[PyQt] qsqltablemodel - ordering results

Dan Kripac dankripac at gmail.com
Thu Sep 2 22:22:18 BST 2010


Hey Tom (hey - don't I work with you? ;-),

Have you tried looking at making a
QAbstractProxyModel<http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qabstractproxymodel.html>
subclass
or even better a
QSortFilterProxyModel<http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qsortfilterproxymodel.html>
class and
putting it between your QSqlTableModel and your QTableView?

You can override the MapFromSource and MapToSource methods and perhaps do
your column swapping in there? Or maybe you could do it all in the sort
filter model?

Cheers
Dan


On 2 September 2010 17:08, Tom Proctor <tmp at dneg.com> wrote:

> I would like to use a subclassed QSqlTableModel to fill a QTableView, but
> I'd like the order of the columns in the table to be different from the
> order of my fields in the database.
>
> I thought there must be some way to modify the query in .select() but I
> haven't gotten that to work.  Using setQuery only seems to prevent queries
> from returning values.
>
> I also tried simply changing horizontalHeader().moveSection() on the table,
> but this is ugly as it needs to be reset each time I filter or select again.
>
> Any ideas?
>
> Thank you,
> Tom
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100902/f7fbe37f/attachment.html>


More information about the PyQt mailing list