[Qt-interest] QTableView/QSqlTableModel: how to set order of columns in header ?
Israel Brewster
israel at frontierflying.com
Mon May 18 19:04:54 CEST 2009
-----------------------------------------------
Israel Brewster
Computer Support Technician II
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------
On May 16, 2009, at 5:55 AM, Stephen Collyer wrote:
> 2009/5/15 Sean Harmer <sean.harmer at maps-technology.com>
> Stephen Collyer wrote:
> > I am populating a QTableView from a QSqlTableModel. I am selecting
> > a set of columns in the model, which we can call A, B, C, D.
> >
> > I want to have the columns displayed by the view in the order
> > C, B, A, D from left to right. Can anyone suggest how I can do
> this ?
> > I can't see anything in the maze of table/view classes that allow
> this
> > to be done.
> I an think of a couple of options:
>
> (i) Use a QSqlQueryModel instead and query for your columsn in the
> required order/
>
> Thanks. This looks like the most appropriate approach for me. I note
> that you can use a preconstructed QSqlQuery to populate the model,
> which in my case works nicely, as I have a set of canned queries in
> another class that I may as well reuse.
If you can use a QSqlQueryModel (i.e. you don't need an editable
model), then yes, that's probably the best option. Not only because
you can query the columns in whatever order you want, but also because
you don't have to worry about the user accidentally changing the data.
However, if you do need to use a QSqlTableModel for whatever reason
(such as if you do want an editable model), then you can rearrange the
columns using the QHeaderView::moveSection(int from, int to) function.
Seems a bit counter-intuitive to me, as I would think that would just
move the headers, not the entire column, but it does work - I'm using
it in my code.
>
> --
> Stephen Collyer
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090518/6ae848f4/attachment.html
More information about the Qt-interest-old
mailing list