Sorting QTableView using QSqlRelationalTableModel
I'm trying to sort a QTableView.
So far I tried to set
@ but nothing happens.
Also I tried @ connect(tableView->horizontalHeader(),SIGNAL(sectionClicked(int)), tableView, SLOT(sortByColumn(int))); @
Any help is greatly appreciated.
You can use QSortFilterProxyModel to enable sorting that you need. You need to subclass QSortFilterProxyModel and implement couple of methods.
Okay, subclassed QSortFilterProxyModel - whats the next step?
Which methods should I implement? And how should they look like?
First of all look at Custom Sort/Filter Model example.
All you need is to reimplement lessThan() method. And of course you need to change all places where you are using indexes of your model (outside of model of course), because you should map them with using QSFPM methods to get your underlying indexes.
"This wiki article":https://developer.qt.nokia.com/wiki/QSqlRelationalDelegate_subclass_that_works_with_QSqlRelationalTableModel may also be relevant.