1 Attachment(s)
Problem at getting text of QTreeWidgetItem
Hi,
I already asked this question in another forum, but I'm not getting any answers,maybe you can help me.
by adding more than one item to my QTreeWidget my program fails to return the text of the 2nd, 3rd,... item. The QString it should return stays empty.
This is how it looks:
Attachment 9387
I’m creating a QTreeWidgetItems and add them to a QTreeWidget in a QDockWidget called “targetInfoWidget_â€.
Code:
bool ok;
tr
("Target Name:"),
QLineEdit::Normal,
"",
&ok
);
if (ok && !text.isEmpty()) {
item->setText(0, text);
}
and then I want to get the selected item in the tree and do stuff with it, depending on the found name of the item.
Code:
int col = targetInfoWidget_->treeWidget->indexOfTopLevelItem(item);
QString itemToAppendName
= item
->text
(col
);
QMessageBox::critical(this,
"item To Append", itemToAppendName
);
The QMessageBoxes are for me to check what the results of the lines are and to get to know at which line the results are not correct anymore.
For the item asd the messages return “0†and “asdâ€. For the Item sdf the messages return “1†and what is shown in picture above.
I'm googling for days now without finding a solution.
Is someone out there who's able to help me?
btw. I'm using Visual Studio 12 to hardcode the Userinterface and not the QtCreator.
Re: Problem at getting text of QTreeWidgetItem
You have to get the item's text from column 0, and index 1.
Code:
int index = targetInfoWidget_->treeWidget->indexOfTopLevelItem(item);
QString itemToAppendName
= item
->text
(0);
QMessageBox::critical(this,
"item To Append", itemToAppendName
);
Re: Problem at getting text of QTreeWidgetItem
awwwwwww maaaan, thank you, this was bothering me vor days :confused: now it works :)