Here's some code I use to expand the tree all the way to the root.
It's a recursive function that accepts a QTreeWidgetItem *item pointer and travels up the tree, starting as position of *item, and expands all parents in the *item's branch until it reaches the *item's topLevelItem.
if (parent) {
parent->setExpanded(true);
int topLevel = table->indexOfTopLevelItem(parent);
if (topLevel!=-1) {
root->setExpanded(true);
} else {
if (item->parent()) {
expandTree(item->parent());
}
}
}
}
void MyWidget::expandTree(QTreeWidgetItem *item) {
QTreeWidgetItem *parent = item->parent();
if (parent) {
parent->setExpanded(true);
int topLevel = table->indexOfTopLevelItem(parent);
if (topLevel!=-1) {
QTreeWidgetItem *root = table->topLevelItem(topLevel);
root->setExpanded(true);
} else {
if (item->parent()) {
expandTree(item->parent());
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks