QSortFilterProxyModel - sort strings
I am using this model with my overidden QAbstractTableModel model. The problem I see with the sort of the QSortFilterProxyModel is it incorrectly sorts my column that contains integers.
For instance, if the data is as follows:
2, 6, 1, 9, 0, 10.
It gets sorted as follows:
0, 1, 10, 2, 6, 9
Obviously, 10 should not follow 1. Is there a way to correctly sort this other than creating my own ProxyModel that derives from QSortFilterProxyModel?
Thanks,
DP
Re: QSortFilterProxyModel - sort strings
Quote:
Originally Posted by DPinLV
For instance, if the data is as follows:
2, 6, 1, 9, 0, 10.
It gets sorted as follows:
0, 1, 10, 2, 6, 9
Obviously, 10 should not follow 1.
Of course it should. The model sorts items according to their text and not numerical value.
Quote:
Is there a way to correctly sort this other than creating my own ProxyModel that derives from QSortFilterProxyModel?
No, you should subclass and reimplement lessThan().
Re: QSortFilterProxyModel - sort strings
Quote:
Originally Posted by wysota
Of course it should. The model sorts items according to their text and not numerical value.
My mistake, I meant that figuratively based on my "interpretations" of the data.:)
Thanks.
Re: QSortFilterProxyModel - sort strings
Quote:
Originally Posted by DPinLV
My mistake, I meant that figuratively based on my "interpretations" of the data.
If you want your interpretations to be considered, you have to implement them yourself. Models in Qt are "string based" -- the variant is always cast to string when using Qt::DisplayRole role. If you desire a different behaviour, you have to provide it yourself. The only component which actually handles more variants in such a situation is an editor factory for the delegate (if it is told so, of course).