PDA

View Full Version : QSortFilterProxyModel - sort strings



DPinLV
29th August 2006, 00:18
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

wysota
29th August 2006, 00:51
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.


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().

DPinLV
29th August 2006, 00:55
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.

wysota
29th August 2006, 01:06
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).