Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Scroll to item in TreeView, positionViewAtIndex seems not work
Forum Updated to NodeBB v4.3 + New Features

Scroll to item in TreeView, positionViewAtIndex seems not work

Scheduled Pinned Locked Moved Solved QML and Qt Quick
treeviewscrollto
2 Posts 1 Posters 736 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xiaowang
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xiaowang
      wrote on last edited by
      #2

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

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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved