selectedRows() on TreeView with ExtendedSelection is one step behind
-
Hi everyone,
I have a treeview in the qml, the selection mode is ExtendedSelection. Whenever the selected index changes by the user I need to exactly know which tree rows are selected. Here is the TreeView:Controls.TreeView { id: myTreeView Controls.TableViewColumn { title: "Name" role: "name" } headerVisible: false anchors.fill: parent selection: ItemSelectionModel { onCurrentIndexChanged: { console.log(myTreeView.selection.selectedRows(0)) console.log(currentIndex) } } selectionMode: Controls.SelectionMode.ExtendedSelection onDoubleClicked: { if (isExpanded(index)) collapse(index); else expand(index); } }
In the example above I just try to print the selected rows to the console to make sure I have the right selection.
currentIndex
always holds the last selected index(as expected), but theselection.selectedRows()
which is supposed to hold all the rows that are currently selected, is always one step behind. For example:if user (while holding Ctrl) selects rows
1, 2, 3
one by one theselection.selectedRows()
will benull, "1", "1,2"
andcurrentIndex
will be1, 2, 3
respectively. Combining these two together, one can get the list of all indexes that are in selected state.
My problem is that if the user releases the Ctrl and selects row4
, then theselection.selectedRows()
will be"1,2,3"
although it should benull
.
To summarize it is not possible to distinguish between the case that the user selects (holding Ctrl) rows1,2,3,4
and the case in which user first selects rows (holding Ctrl)1,2,3
and then releases Ctrl and just selects row4
.I have also tested with
myTreeView.selection.selectedIndexes
, but still the same behaviour.
It looks like a bug in TreeView to me, please advice how to solve.Thanks.