[Solved] Qt - How to get parent of QTreeWidgetItem
-
Hi,
Does anyone know how to get parent of a QTreeWidgetItem child?
Thanks!!
-
Yes...I suppose I worded my question incorrectly, but thank you.
I meant how can I return the string of the parent in C++ as that method returns a QTreeWidgetItem.
-
:) Thanks, DerManu again!
I tried:
treeWidgetItem->parent()->text(column)
Works!!
-
Thank you, Andre. I also noticed that it would crash if the item was the uppermost item & had no parent.
I added this check to my c++ code (might be useful for anyone who comes across this in the future):
@ QString cur = item->text(column); int root = ui->treeWidget->indexOfTopLevelItem(item); if ( root.parent() != None ) { // not top most QString parent = item->parent()->text(column); }@