Search code examples
qtindexingtreeviewqmlqt-quick

How to get currentIndex of an delegateItem in a TreeView


Hellow,

When using delegate on a Column, how could I know the index of the Cell or Row selected if the user clicks on the delegateItem ?

Here is an example. The second Column is a MouseArea and I want to expand the currentIndex when the user clicks on the MouseArea:

TreeView {
    id: view
    TableViewColumn {
        title: "Name"
        role: "fileName"
        width: 300
    }
    TableViewColumn {
        title: "Permissions"
        role: "filePermissions"
        width: 100
        delegate : MouseArea {
            id:mous
            onClicked {
                 //get indexMouseArea
                 view.expand(indexMouseArea)
            }
        }
    }
    model: fileSystemModel

    onExpanded {
       console.log("expanded :" + index)
    }
}

Solution

  • Solution thanks to @mcchu:

    Hellow,

    When using delegate on a Column, how could I know the index of the Cell or Row selected if the user clicks on the delegateItem ?

    Here is an example. The second Column is a MouseArea and I want to expand the currentIndex when the user clicks on the MouseArea:

    TreeView {
        id: view
        TableViewColumn {
            title: "Name"
            role: "fileName"
            width: 300
        }
        TableViewColumn {
            title: "Permissions"
            role: "filePermissions"
            width: 100
            delegate : MouseArea {
                id:mous
                onClicked {
                    view.expand(styleData.index);
                }
            }
        }
        model: fileSystemModel
    
        onExpanded {
           console.log("expanded :" + index)
        }
    }