Results 1 to 4 of 4

Thread: QSortFilterProxyModel - sort strings

  1. #1
    Join Date
    Jul 2006
    Posts
    33
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default 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
    Last edited by DPinLV; 29th August 2006 at 00:34.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

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

  3. The following user says thank you to wysota for this useful post:

    DPinLV (29th August 2006)

  4. #3
    Join Date
    Jul 2006
    Posts
    33
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

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

Similar Threads

  1. Drag and drop items in view to sort order
    By Big Duck in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2006, 19:43
  2. Sort datatable
    By zlatko in forum Qt Programming
    Replies: 1
    Last Post: 10th May 2006, 08:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.