如何在TreeView中获取delegateItem的currentIndex

时间:2017-05-21 06:56:50

标签: qt indexing treeview qml qt-quick

Hellow,

delegate上使用Column时,如果用户点击Cell,我怎么知道所选RowdelegateItem的索引?

这是一个例子。第二个ColumnMouseArea,当用户点击expand时,我希望currentIndex 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)
    }
}

1 个答案:

答案 0 :(得分:0)

感谢@mcchu解决方案:

Hellow,

在列上使用委托时,如果用户单击delegateItem,我怎么知道所选单元格或行的索引?

这是一个例子。第二列是MouseArea,我想在用户点击MouseArea时展开currentIndex:

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)
    }
}