{
if (item->parent())
{
compute_index(tree, item->parent(), index);
index = index.child(item->parent()->indexOfChild(item), 0);
}
else
{
index = tree->model()->index(tree->indexOfTopLevelItem(item), 0);
}
}
// Later, given item and treeWidget:
compute_index(treeWidget, item, index);
treeWidget->scrollTo(index);
void compute_index(QTreeWidget* tree, QTreeWidgetItem* item, QModelIndex& index)
{
if (item->parent())
{
compute_index(tree, item->parent(), index);
index = index.child(item->parent()->indexOfChild(item), 0);
}
else
{
index = tree->model()->index(tree->indexOfTopLevelItem(item), 0);
}
}
// Later, given item and treeWidget:
QModelIndex index;
compute_index(treeWidget, item, index);
treeWidget->scrollTo(index);
To copy to clipboard, switch view to plain text mode
Bookmarks