PDA

View Full Version : QTreeWidgetItem problems



rulfen
9th May 2011, 21:11
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?




QTreeWidgetItem* LabelingWidgetQt::iterateTreeWidget(QTreeWidgetIte m* parent, QString str)
{
int count = parent ? parent->childCount() : treeWidget_->topLevelItemCount();

for (int i = 0; i < count; i++)
{
QTreeWidgetItem* item = parent ? parent->child(i) : treeWidget_->topLevelItem(i);


if(item->text(0)==str){
return item;
}

iterateTreeWidget(item,str);
}
return 0;
}


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



QTreeWidgetItem* item = new QTreeWidgetItem();
item->setText(0, QString::fromStdString(name));

QTreeWidgetItem* parentItem = iterateTreeWidget(0,QString::fromStdString(parent) );
if(parentItem){
parentItem->addChild(item);
}


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.



QTreeWidgetItem* groupItem;

if(parent == "root"){
groupItem = new QTreeWidgetItem(treeWidget_);
groupItem->setText(0, QString::fromStdString(name));
} else {
QTreeWidgetItem* parentItem = iterateTreeWidget(0,QString::fromStdString(parent) );
groupItem = new QTreeWidgetItem(parentItem);
groupItem->setText(0, QString::fromStdString(name));
}


Thanks for any help!

rulfen
10th May 2011, 07:16
Problem solved. .)