[PyQt] qsqltablemodel - ordering results

Tom Proctor tmp at dneg.com
Fri Sep 3 08:45:52 BST 2010


Hey Dan,

Thanks, I will check out the classes you suggest.  I have also had some 
success with QSqlQueryModel instead of QSqlTableModel, by setting the 
query in such a way as to return the values in the order I want them.

Cheers,
Tom

Dan Kripac wrote:
> 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 
> <mailto: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
>     <mailto: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/20100903/928af7ed/attachment.html>


More information about the PyQt mailing list