Francisco Hernandez
Francisco Hernandez

Reputation: 312

How to get the current row of a QML TreeView?

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?

Upvotes: 0

Views: 1290

Answers (1)

Tarod
Tarod

Reputation: 7170

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.

Upvotes: 1

Related Questions