Results 1 to 2 of 2

Thread: QTreeWidgetItem problems

  1. #1
    Join Date
    May 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeWidgetItem problems

    Hi,

    I'm trying create a QTreeWidgetList with multiple parents
    root->parent->another parent->item

    I'm adding the items by traversing through the already added parents and selecting the correct one by searching after the name of the parent. This works good until I try to add items to "another parent" then it returns null even if it have found correct parent node. Can anyone help me figure out what is happening?


    Qt Code:
    1. QTreeWidgetItem* LabelingWidgetQt::iterateTreeWidget(QTreeWidgetItem* parent, QString str)
    2. {
    3. int count = parent ? parent->childCount() : treeWidget_->topLevelItemCount();
    4.  
    5. for (int i = 0; i < count; i++)
    6. {
    7. QTreeWidgetItem* item = parent ? parent->child(i) : treeWidget_->topLevelItem(i);
    8.  
    9.  
    10. if(item->text(0)==str){
    11. return item;
    12. }
    13.  
    14. iterateTreeWidget(item,str);
    15. }
    16. return 0;
    17. }
    To copy to clipboard, switch view to plain text mode 

    Here I create the Item and adds it to the found parent node.

    Qt Code:
    1. item->setText(0, QString::fromStdString(name));
    2.  
    3. QTreeWidgetItem* parentItem = iterateTreeWidget(0,QString::fromStdString(parent));
    4. if(parentItem){
    5. parentItem->addChild(item);
    6. }
    To copy to clipboard, switch view to plain text mode 

    I'm using the same iterate method to add the parents/groups and this works fine and I can have multiple parents, but I cannot add items to the multiple parents, only to the topLevelItems.

    Qt Code:
    1. QTreeWidgetItem* groupItem;
    2.  
    3. if(parent == "root"){
    4. groupItem = new QTreeWidgetItem(treeWidget_);
    5. groupItem->setText(0, QString::fromStdString(name));
    6. } else {
    7. QTreeWidgetItem* parentItem = iterateTreeWidget(0,QString::fromStdString(parent));
    8. groupItem = new QTreeWidgetItem(parentItem);
    9. groupItem->setText(0, QString::fromStdString(name));
    10. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for any help!

  2. #2
    Join Date
    May 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidgetItem problems

    Problem solved. .)

Similar Threads

  1. QTreeWidgetItem
    By bismitapadhy in forum Qt Programming
    Replies: 12
    Last Post: 7th January 2011, 10:48
  2. Replies: 5
    Last Post: 23rd September 2010, 13:58
  3. :( Problems with QTreeWidgetItem icons
    By davit in forum Qt Programming
    Replies: 13
    Last Post: 18th April 2007, 13:38
  4. QTreeWidgetItem
    By Sarma in forum Qt Programming
    Replies: 1
    Last Post: 6th April 2006, 19:52
  5. QTreeWidgetItem
    By raphaelf in forum Qt Programming
    Replies: 4
    Last Post: 5th March 2006, 15:07

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.