QTreeView::sortByColumn(int column, Qt::SortOrder order) Why does this function sort not by numbers but by characters
-
QTreeView::sortByColumn(int column, Qt::SortOrder order)
Why does this function sort not by numbers but by characters -
@eyllanesc
The ascending order of this function is to put 10 before 2, 3, 4, 5, etc., which is obviously sorted by character -
@duncan98 I understand the behavior you describe but the default ordering assuming it is a string, so if you want to change that criterion, you must modify the model, and for that reason I need the example that I asked if you want help.
-
@eyllanesc
I'm going to give up Qt -
@duncan98 said in QTreeView::sortByColumn(int column, Qt::SortOrder order) Why does this function sort not by numbers but by characters:
I'm going to give up Qt
Excellent, far better than providing an example :)
In any case: it sorts with whatever type is in the column in the model. If that is a number type it will sort numerically, if that is a string type it will sort alphabetically.
-
Hi,
Using a custom QSortFilterProxyModel with QCollator using the numeric mode should give you the results you want.
-
I'm also interested in the topic
I use QStandardItemModel adding items manually.I want the items to be displayed with coma as decimal separator but then the sorting with QSortFilterProxyModel will consider those cells QStrings.
Is that the use case for QCollator @SGaist or is there something easier to have number with local decimals and still be able to sort as numbers? -
@Seb-Tur Don't add the values as QString but as numbers. -> QStandardItem::setData(value, Qt::DisplayRole)