Results 1 to 2 of 2

Thread: Qt needs a sub item tree iterator

  1. #1
    Join Date
    Apr 2010
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Qt needs a sub item tree iterator

    Thinking to save time writing a recursive function that would process all siblings and children from a given level in a QTreeWidget, I created a QTreeWidgetItemIterator using the item I wanted the iterator to start from in the constructor. All worked wonderfully until it reached the end of that branch, where I would expect the iterator to finish. But, against all common sense, it stepped up to the parent of the original item and started processing its siblings. I've never come across an iterator that behaves this way, so i checked the source to see if my eyes were deceiving me. And wouldn't you know it; look what I found...

    [qtreewidgetitemiterator.cpp, line: 300] // if we had no sibling walk up the parent and try the sibling of that

    ...obviously it was designed to behave like a list (rows) iterator rather than a heirachial (siblings and child branches) iterator.

    Would it be too much to ask for an iterator to traverse a given level in a tree, with the option to process child items? Or how about methods to access the next/prev sibling without having to access the QModelIndex of the current item?

  2. #2
    Join Date
    Apr 2010
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt needs a sub item tree iterator

    For those that are interested, the trick to traversing sibling items is to check if the parents are the same.

    if((*it)->parent() == item->parent())

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

    alketi (5th March 2020)

Similar Threads

  1. Tree View Item selected rectangle
    By LynneV in forum Qt Programming
    Replies: 2
    Last Post: 28th May 2010, 17:17
  2. Replies: 1
    Last Post: 18th November 2008, 07:57
  3. Checkable item in tree model
    By zlatko in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2007, 12:35
  4. how to display full tree item name on mouse move ?
    By rajesh in forum Qt Programming
    Replies: 5
    Last Post: 15th November 2006, 09:41
  5. Replies: 14
    Last Post: 9th November 2006, 09:35

Tags for this Thread

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.