Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Sort QTableWidget by two colums
AndreaCT last edited by
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.
JonB last edited by JonB
I am not aware of that possibility for QTableWidget.
[virtual]bool QTableWidgetItem::operator<(const QTableWidgetItem &other) const, https://doc.qt.io/qt-5/qtablewidgetitem.html#operator-lt. If
QTableWidgetcalls this method for sorting items (I don't know whether it does, but hopefully that's why it's there), if @AndreaCT subclasses
QTableWidgetItemfor 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?