Results 1 to 3 of 3

Thread: List all elements of a QTreeWidget from top to bottom

  1. #1
    Join Date
    May 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy List all elements of a QTreeWidget from top to bottom

    I'm having dificulties getting all the values of a N levels QTreeWidget by the folloying order:

    For example:

    A1
    B1
    B2
    B3
    C1
    C2
    D1
    D2
    C3

    and i want to put them in an array like: A1 B1 B2 B3 C1 C2 D1 D2 C3

    I'm having big problems trying to find this algorithm. For a finit levels tree i can do it but for N its more dificult.

    Someone can help me with this?

    Maybe i can use the model for that?

  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: List all elements of a QTreeWidget from top to bottom

    I'm not sure if I follow what you mean by the letters and numbers but isn't that a simple case of descending node traversal using a recursive call? First "visit" yourself, then visit each of your children in order by calling the same visiting function on them.

    Something like:
    Qt Code:
    1. void visitTree(QStringList &list, QTreeWidgetItem *item){
    2. list << item->text(0);
    3. for(int i=0;i<item->childCount(); ++i)
    4. visitTree(list, item->child(i));
    5. }
    6.  
    7. QStringList visitTree(QTreeWidget *tree) {
    8. for(int i=0;i<tree->topLevelItemCount();++i)
    9. visitTree(list, tree->topLevelItem(i));
    10. return list;
    11. }
    12. //...
    13. QStringList result = visitTree(myTree);
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: List all elements of a QTreeWidget from top to bottom

    Thanks a lot. It solved my problem

Similar Threads

  1. not able move across elements in QTreeWidget
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2010, 20:35
  2. Cursor is not moving through QTreeWidgetItem list in QTreeWidget
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 0
    Last Post: 11th December 2009, 07:52
  3. Why QStatusBar do not at the bottom?
    By FinderCheng in forum Qt Programming
    Replies: 5
    Last Post: 29th September 2009, 09:26
  4. Replies: 7
    Last Post: 15th November 2007, 18:19
  5. widgets on bottom
    By kernel_panic in forum Qt Programming
    Replies: 6
    Last Post: 19th October 2007, 21:07

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.