Results 1 to 4 of 4

Thread: Issue with Ordering of selected Nodes in a QTreeView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,330
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Issue with Ordering of selected Nodes in a QTreeView

    And since you are selecting on multiple levels of the tree hierarchy, your sort condition needs to not only take into account the row, but also the parent-child relationship of those rows. (E.g. both "Path 1902" and "path_group" could have a row index of zero).

    This would be especially important if you selected two top-level groups - then you would have duplicate row indexes for each of the two "Path" parents.

    If what you want to do is to allow extended selection, but in effect select all children of the selected "Path" nodes, then I would iterate over the returned list of QModelIndex entries, pull out only the Path nodes into another list and sort that new list by row number. Then I would go over that sorted list and pull all of the child nodes of each Path node out of the model and insert those into the sorted list following their parent Path node. Everything will then be in the same order as it appears in the tree.

    In effect, you ignore the child nodes returned by the initial selection, but then go back into the model and pull out the complete list of them based on the Path nodes that were selected.
    Last edited by d_stranz; 14th September 2018 at 17:48.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Simple way to expand all nodes on a QTreeView?
    By cboles in forum Qt Programming
    Replies: 10
    Last Post: 12th April 2014, 16:54
  2. QTreeView select parent nodes
    By mqt in forum Qt Programming
    Replies: 2
    Last Post: 1st August 2013, 05:01
  3. Replies: 0
    Last Post: 22nd October 2011, 12:52
  4. Replies: 1
    Last Post: 28th February 2007, 08:34
  5. [QT4] QTreeView and expandable nodes
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2006, 16:52

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.