Results 1 to 3 of 3

Thread: QSortFilterProxyModel and QTreeView

  1. #1
    Join Date
    Jan 2006
    Posts
    17
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QSortFilterProxyModel and QTreeView

    I need to do a slightly more complex sort on strings for a QTreeView. The 1st level nodes all need to be sorted by string but the sort needs to be more complex than normal alphabetical, I need to sort based off of sub strings . Here is a simple example:

    Given strings: AA1, AA2, AB1, AB2

    I need to sort based on first character; then last character; and then middle character. So to get the proper new sort order I would need the result to be:

    AA1
    AB1
    AA2
    AB2

    The strings were sorted on the first character (A) using normal alphabetic, then sorted on the third character (the numbers) and lastly the middle character to get this result.

    Hopefully that makes sense.

    I'm not sure if I can use a QSortFilterProxyModel to do this character based sorting ONLY on the first level of nodes (not the children) in a QTreeView.

    Thanks

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSortFilterProxyModel and QTreeView

    You can provide your custom comparison method by overriding QSortFilterProxyModel::lessThan

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 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 and QTreeView

    You can also add a custom role to your base model that will return the data in a format appropriate for sorting and use that role for sorting by calling QSortFilterProxyModel::setSortRole().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QTreeView repaint
    By graeme in forum Qt Programming
    Replies: 17
    Last Post: 13th March 2012, 13:27
  2. Direct root childs inline QTreeView
    By faraslacks in forum Qt Programming
    Replies: 2
    Last Post: 15th January 2009, 07:45
  3. QDirModel and QTreeView cut and paste
    By Micawber in forum Qt Programming
    Replies: 4
    Last Post: 28th May 2008, 20:16
  4. QTreeView help
    By bepaald in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 21:22
  5. QTreeView: Holding a line on screen
    By gri in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 11:42

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.