PDA

View Full Version : any solution to QtableView sorting?



KillGabio
23rd January 2012, 03:39
i ve read in this forum the next statement

Hi

Using Qt 4.1.3 (release, linux)

The actual problem is in QTableView.
It is not possible to enable sorting in QTableView as the actual connect to sortByColumn is made in QTableWidget and not in QtableView.
If you compare this with QTreeView, you'll notice that these connects are moved to QTreeView.
This should be done by Trolltech guys as well for QTableView.
Just compare code difference in qt source where they connect sortByColumn and you'll understand.

BTW: When using sort function in your widget you'll notice that the sort works fine in QTableView. Only the connections when clicking the header are made at the wrong place (In QTableWidget instead of in QTableView).

I hope this explains the original problem in this topic.
And I hope they come with a fix. By the way I did not check snapshot code to see if it is already fixed.


in fact im working with a QTableView that is connected to a QsqlQueryModel, the problem is that when i do


tableView.setSortingEnabled (true)
or

tableView.sortByColum (0, Qt::AscendingOrder)

for example, it has no effect...

any solution with QtableView? shoul i change this to a QtableWidget?

thanks everyone

ChrisW67
23rd January 2012, 21:44
I would expect it to work as-is, but I haven't tried exactly the combination you are complaining about.

If you just want the data sorted in one way, and not user controlled, then just put an "ORDER BY" clause into your SQL.

If you want user control of sorting then try putting a QSortFilterProxyModel between the base model and your view.

KillGabio
25th January 2012, 20:12
SOLVED!! using QsortFilterProxyModel thankkkks!