QTreeView::sortByColumn(int column, Qt::SortOrder order) Why does this function sort not by numbers but by characters
-
-
@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)