Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Scroll to item in TreeView, positionViewAtIndex seems not work



  • 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.



  • It should be used as following:
    __listView.positionViewAtIndex(treeView.currentIndex.row, treeView.Beginning)

    And it works when the treeview's length is enough long.



  • It should be used as following:
    __listView.positionViewAtIndex(treeView.currentIndex.row, treeView.Beginning)

    And it works when the treeview's length is enough long.


Log in to reply