Unsolved Sort QTableWidget by two colums
-
Hi! Is possible to sort a QTableWidget by two columns?
I use sortItems(column, Qt::DescendingOrder) to sort by single column, but I would also sort the equal values by another columns.
Thanks
-
Hi,
I am not aware of that possibility for QTableWidget.
However you can change that with a QTableView, QSortFilterProxyModel, QStandardItemModel and do that with a custom QSortFilterProxyModel. -
@SGaist said in Sort QTableWidget by two colums:
I am not aware of that possibility for QTableWidget.
QTableWidgetItem
has[virtual]bool QTableWidgetItem::operator<(const QTableWidgetItem &other) const
, https://doc.qt.io/qt-5/qtablewidgetitem.html#operator-lt. IfQTableWidget
calls this method for sorting items (I don't know whether it does, but hopefully that's why it's there), if @AndreaCT subclassesQTableWidgetItem
for the items he adds into the table, he can override that and see if works? At least well enough to deal with other columns when sorted column values are equal?