Results 1 to 15 of 15

Thread: QListView sorting

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Somewhere in the middle of the State of New York
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    4

    Default Re: QListView sorting

    Right,
    Sorry About that, havent used QT3 in a while or QT4, I'm getting rusty
    in QT3 QListView you need to reimplement compare()
    see this thread
    "Power, The only Thing Better than Toast" -- Blitzen The Evil Reindeer

  2. #2
    Join Date
    Mar 2007
    Posts
    31
    Qt products
    Qt3
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: QListView sorting

    I've reimplemented compare in this way:

    Qt Code:
    1. int KMListViewItem::compare(QListViewItem * i, int col, bool ascending) const
    2. {
    3. qDebug("compare()");
    4.  
    5. Q_UNUSED(i);
    6. Q_UNUSED(col);
    7. Q_UNUSED(ascending);
    8.  
    9. return 0;
    10. }
    To copy to clipboard, switch view to plain text mode 

    It should work but it doesn't (items are moved). I think the only solution is to use setSorting(-1) and then use QHeader's setSortIndicator.

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

    Default Re: QListView sorting

    Try implementing a real compare function. This one is not valid.

  4. #4
    Join Date
    Mar 2007
    Posts
    31
    Qt products
    Qt3
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: QListView sorting

    Quote Originally Posted by fear View Post
    I think the only solution is to use setSorting(-1) and then use QHeader's setSortIndicator.
    I made it this way and now it works! Reimplementing compare() isn't good idea because list view will still iterate over items.

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

Similar Threads

  1. QListView word wrap
    By serega in forum Qt Programming
    Replies: 17
    Last Post: 30th August 2007, 04:13
  2. Subclass QListView to show two colums in one
    By Mookie in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2007, 03:12
  3. Items in QListView should sort on Header Click
    By vinnu in forum Qt Programming
    Replies: 14
    Last Post: 10th November 2006, 13:49
  4. How can I disable the QListView Sorting?
    By darpan in forum Qt Programming
    Replies: 3
    Last Post: 27th June 2006, 11:36
  5. [QT4] QTreeView, QAbstractItemModel and sorting
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th March 2006, 21:16

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
  •  
Qt is a trademark of The Qt Company.