Qt provides QTreeWidgetItemIterator class to iterate through tree view's items. There is even a constructor version which takes the item pointer instead of a view's. Unfortunately, even in this case, the iteration will go down to the very last item. Often, that is not expected behavior. If I start from the item, I want iterate only it's children and grandchildren. Of course, I could get another loop up the tree to check if I didn't go beyond the starting item, but that's ugly. Is there way to do this nicely?
QTreeWidgetItemIterator it(treeWidget);
while (*it) {
if ((*it)->text(0) == itemText)
(*it)->setSelected(true);
++it;
}