Qt: Sorting is wrong when using QSortFilterProxyModel on number strings and getting wrong column text

后端 未结 3 657
梦如初夏
梦如初夏 2021-01-06 19:19

i have simple model view treeview with QSortFilterProxyModel proxy to sort the columns and QStandardItemModel as the model
in each columns there are string that gets sor

3条回答
  •  执笔经年
    2021-01-06 19:50

    If you sort the strings "9", "12" and "1" you will get "1", "12", "9" (lexicographic sorting). If you want them sorted as numbers, you have to subclass the QSortFilterProxyModel and reimplement the lessThan member function where you could just use QString::toInt().

    You can find out all of this by studying the excelent Qt documentation, where you also find information about mapToSource(), mapFromSource(), mapSelectionToSource(), and mapSelectionFromSource() to convert source QModelIndexes to sorted/filtered model indexes or vice versa.

提交回复
热议问题