Results 1 to 4 of 4

Thread: [QT4] QTreeView, QAbstractItemModel and sorting

  1. #1
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Question [QT4] QTreeView, QAbstractItemModel and sorting

    Hello all...

    I'd thought I'd attempt to implement some sorting algorithms for my tree... and noticed a virtual function in QAbstractItemModel that handles sorting (which does nothing if not re-implemented). I went ahead and re-implemented that function... and found that it doesn't seem to get activated when I click on a heading.

    I'm not positive that Qt by default does sorting when you click on a heading, so my first question is how to make that happen.

    If it does, what else do I need to look at to enable sorting?

    Thanks
    Life without passion is death in disguise

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: [QT4] QTreeView, QAbstractItemModel and sorting

    At least the header needs to set clickable..
    Qt Code:
    1. view->header()->setSortIndicatorShown(true); // optional
    2. view->header()->setClickable(true);
    To copy to clipboard, switch view to plain text mode 

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

    KShots (24th March 2006)

  4. #3
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: [QT4] QTreeView, QAbstractItemModel and sorting

    Thanks, that plus emitting a dataChanged signal in my model was all I needed. It works fine now

    Puzzled note: Why didn't I get an e-mail that someone responded to this msg? Odd...

    EDIT: Now that I think of it, the dataChanged() signal has two variables contained within it: QModelIndex & topLeft and QModelIndex & bottomRight. This makes sense for a table model, and can easily make sense for a list model... but what the heck is the bottom right of a tree?

    Would that be the last item under the root node, or the last item of the deepest node?
    Last edited by KShots; 24th March 2006 at 21:23.
    Life without passion is death in disguise

  5. #4
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Question Re: [QT4] QTreeView, QAbstractItemModel and sorting

    One last question:

    How can I disable the sort indicator for a specific column? There are some columns in my model that sorting would make no sense on. My sort function does nothing on them, but the sort indicator shows up and flips around when I click on them.

    I would have hoped for a view->header()->setClickable(int logicalIndex, bool clickable) type function, but I don't see one.
    Life without passion is death in disguise

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.