Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How can I select a child node in a QTreeView?
nzur last edited by VRonin
Hi, I have a QTreeView with nested nodes, I need to select a child node according to an index in a table.
Here's what I do:
QModelIndex nIndex = view.model()->index(tableIndex, 0); view.selectionModel()->clearSelection(); view.selectionModel()->select(nIndex, QItemSelectionModel::Select | QItemSelectionModel::Rows); view.scrollTo(nIndex);
for example: when
tableIndex == 3I expect to select the 3rd child node, but this selects the 3rd parent row
The third child node of what ? Overall ? Of the top level item ? Of the third top level item ?
VRonin last edited by
You are missing the 3rd argument of index. How can it know what parent to take it from? for example, for the third child of the first parent:
QModelIndex nIndex = view.model()->index(tableIndex, 0, view.model()->index(0,0));
nzur last edited by
Thx, That's it!!!