0

Is there a way to get the row number of a QML TreeView when selecting/clicking something on the TreeView? For example, for a TableView I use currentRow. Is there something equivalent for a TreeView?

1 Answers1

1

You should use currentIndex. More info in the documentation.

For example:

TreeView {
    id: myTree
    ...
    model: myModel

    onCurrentIndexChanged: console.log("current index: " + currentIndex
                                       + " current row: " + currentIndex.row)

    TableViewColumn {
        title: "title1"
        role: "role1"
    }

    TableViewColumn {
        title: "title2"
        role: "role2"
    }

    onClicked: {
        console.log("clicked", index)
    }
}

You can check the complete example in GitHub.

Tarod
  • 6,732
  • 5
  • 44
  • 50