How can I select a child node in a QTreeView?
Unsolved
General and Desktop
-
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 == 3
I expect to select the 3rd child node, but this selects the 3rd parent row -
Hi,
The third child node of what ? Overall ? Of the top level item ? Of the third top level item ?
-
@nzur said in How can I select a child node in a QTreeView?:
index(tableIndex, 0)
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));