Tablesort
-
I want my table to be always sorted alphabetically by its second column after it was sorted by another.
Like if i have 3 cells in column 2 that all have the same value I want those three rows to be sorted by its first column
not sorted:
hello | 1 my | 5 friends | 1
sorted by second column ('hello' and 'friends' are wrong):
hello | 1 friends | 1 my | 5
sorted by second column (preferred):
friends | 1 hello | 1 my | 5
-
Hi,
You might be interested by the QxtSortFilterProxyModel class.
-
I don't want to use Qxt, I don't even know what that is
-
why isn't there a setter for "defaultSortColumn" or something like that....
And why can't I override QTableWidget::sortItems to do that myself.... -
@Megamouse said in Tablesort:
I don't want to use Qxt, I don't even know what that is
Then before saying no, you could take the time to check. Note, that in this case, it won't help you, I mixed filtering and sorting so whatever...
@Megamouse said in Tablesort:
why isn't there a setter for "defaultSortColumn" or something like that....
And why can't I override QTableWidget::sortItems to do that myself....Because for more advanced sorting and filtering there's QSortFilterProxyModel.
-
wow that's awfully complicated for a common feature like that
-
QTableWidget is a convenience class - if you need more control over the data you have to use QTableView and a custom model.
For you problem it should be enough to derive from QTableWidgetItem and override
operator <(const QTableWidgetItem &o) const -
thx. I forgot I already have that operator override, I'll adjust it accordingly.