Qt World Summit: Submit your Presentation

QML TreeView set active item

  • 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?


  • This post is deleted!

  • 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!

  • 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 ?

Log in to reply