Results 1 to 4 of 4

Thread: depth of QTreeWidgetItem

  1. #1
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default depth of QTreeWidgetItem

    hi.
    I'm having a problem with QTreeWidget. i have tree data of unknown depth (readed from XML file), so i'm wondering which is the easiest way to get depth of selected item, so i could take needed indexes of all its parents.
    for illustartion, some code:
    Qt Code:
    1. class cdNamespace
    2. {
    3. public:
    4. cdNamespace();
    5.  
    6. qint32 ID;
    7. QString Name;
    8. QString Description;
    9. QVector<cdObject> Objects;
    10. qint32 NumberOfObjects(void);
    11. QVector<cdNamespace> Namespaces;
    12. qint32 NumberOfNamespaces(void);
    13. }
    To copy to clipboard, switch view to plain text mode 
    My tree control is having unknown depth trough namespaces, and i need to know which namespace is selected. objects are also displayed in tree, which make this even more difficult.
    I have an idea to to this with recursive function, but maybe there is an esier way?

    thanx

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

    Default Re: depth of QTreeWidgetItem

    Qt Code:
    1. int depth = 0;
    2. QTreeWidgetItem *item = ...;
    3. while(item!=0){
    4. depth++;
    5. item = item->parent();
    6. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: depth of QTreeWidgetItem

    So simple Thanx

  4. #4
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: depth of QTreeWidgetItem

    Ok depth is working fine. Now i need to get item index.
    This shoud give index of item:
    Qt Code:
    1. qint32 _Index=_Item->parent()->indexOfChild(_Item);
    To copy to clipboard, switch view to plain text mode 
    but it's not working. Hint?

    -=# EDITED #=-
    SORRY, my fault, itme has no parent.
    Last edited by stefan; 29th June 2008 at 13:06.

Similar Threads

  1. Custom QTreeWidgetItem context menu?
    By AaronMK in forum Qt Programming
    Replies: 4
    Last Post: 1st February 2010, 05:42
  2. Replies: 3
    Last Post: 26th April 2008, 19:42
  3. select a QTreeWidgetItem
    By mattia in forum Newbie
    Replies: 2
    Last Post: 21st December 2007, 12:01
  4. Qtopia depth problem
    By paralyze in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 11th May 2007, 19:35
  5. QTreeWidgetItem swap or move up one level problem
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2006, 19:34

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.