I have a QTableWidget and the first column contains numbers from 1 to 1000. Now I need to sort the table based on this first column.
I’m using the function sortItems(int column, Qt::AscendingOrder), but it is displayed as:
1, 10, 100, 1000, 101, 102, …
Yet I need this result:
1, 2, 3 ,4…., 1000.
I’m using a CSV file for populating the table.
The easiest way is probably to subclass QTableWidgetItem and then implement the < operator to be smart about the fact that you’re sorting numbers and not strings.
Then when you’re populating your table you can pass it instances of your custom items that know how to sort themselves properly instead of the generic ones.