PDA

View Full Version : Reorder the columns in QSqlTableModel/QTableView?



gfunk
17th July 2006, 22:55
In Qt4.1.4, is there a way to dynamically reorder the columns displayed when you tie a QSqlTableModel to a QTableView? I don't seem to see a way to set the columns displayed, except by reordering the actual columns when the table is initially created in "create table" command. For instance, I might want to show the Firstname column before Lastname in one view, and Lastname before Firstname in another view.

jpn
17th July 2006, 23:19
QHeaderView::moveSection (http://doc.trolltech.com/4.1/qheaderview.html#moveSection)(int from, int to)

Moves the section at visual index from to occupy visual index to.

And you can access the header by:
QTableView::horizontalHeader() (http://doc.trolltech.com/4.1/qtableview.html#horizontalHeader)

gfunk
17th July 2006, 23:30
Doh!! I feel bad, that was probably too easy for you. =P
Thanks!