Scroll to item in TreeView, positionViewAtIndex seems not work
Solved
QML and Qt Quick
-
I'm trying to scroll an item to the top of treeView, and used "__listView.positionViewAtIndex(row, mode)", but it seems not work. The main qml code is as following.
TreeView {
id: treeView anchors.top: header.bottom anchors.left: parent.left width: parent.width - 30 anchors.bottom: parent.bottom clip: true style: treeViewStyle backgroundVisible: false alternatingRowColors: false frameVisible: false headerVisible: false horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff verticalScrollBarPolicy: Qt.ScrollBarAlwaysOn flickableItem.interactive: true TableViewColumn { title: "DevTypeName" role: "modelDevTypeName" width: parent.width elideMode: Text.ElideLeft } model: deviceInspectionModel itemDelegate: deviceDelegate rowDelegate: Rectangle { height: 46 color: panelTheme.palette.backgroundColor } property bool isCollapse: true onClicked: { if (isCollapse) { console.log("expand") emit: treeView.expand(index); __listView.positionViewAtIndex(index, TreeView.Beginning ) isCollapse = false; } else { console.log("collapse") emit: treeView.collapse(index); isCollapse = true; } } }
Any Idea?
Thanks.