QML TreeView set active item
-
wrote on 13 May 2015, 18:26 last edited by
Hi,
Does anyone know how to set the active item in a QML TreeView from javascript?
The currentIndex property is read-only. Is there any way to set the index?Thanks
-
wrote on 14 Jul 2015, 08:46 last edited byThis post is deleted!
-
wrote on 14 Jul 2015, 09:41 last edited by
Ok, I have solved this.
import QtQml.Models 2.2
TreeView {
id: viewPerSe
selection: ItemSelectionModel {
model: viewPerSe.model
}
}
function select (idx) {
viewPerSe.selection.setCurrentIndex(idx, ItemSelectionModel.ClearAndSelect)
}You are welcomed!
-
wrote on 16 Sept 2015, 08:49 last edited by
Hi,
Sorry for replying to this old topic but I have a similar problem :
I would like to set the currentIndex (which is read only for a TreeView) in order to navigate throught items from the given currentIndex using the keyboard.
Settings selection is OK, but it does NOT set the currentIndex, so pressing down arrow selects the first item of the TreeView, as currentIndex is still undefined at this step...
Here some code to select :
var index = controller.activeFolderIndex;
treeViewSelectionModel.setCurrentIndex(index, ItemSelectionModel.ClearAndSelect);
//then I would like something like : treeView.currentIndex = index;Any idea ?