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

Can't scroll content of a ScrollView



  • I have created a visual item (treeMenu) which is 3/4 the height of my screen. When I reduce the height of my screen to cutoff my item I want a vertical scroll bar to appear. I have followed advice online and while there is a scrollbar (which appears only when I hover the treeMenu, regardless of window size), it doesn't scroll my item.

    What is wrong with the below? Does the scrollbar not work because Rectangle is a child? I don't want the scrollbar IN the rectangle if possible

    ScrollView {
        ScrollBar.vertical: ScrollBar {
            policy: treeMenu.contentHeight > treeMenu.height ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff
        }
    
        clip: true
        id: treeMenu
        anchors.fill: parent
        contentHeight: rect.implicitHeight
        contentWidth: rect.implicitWidth
        Rectangle {
            id: rect
            anchors.fill: parent
            // A bunch of stuff here
        }
    }
    

    I tried removing the Rectangle wrapper, and then my "bunch of stuff" scrolled up and down with the scrollwheel of my mouse, but the scroll bar still did nothing.


  • Moderators

    @ocgltd you dent set content width and continent hight of your ScrollView -> its the same as the actual width and height -> no scrollbar



  • I tried settings the contentHeight of the Scrollview, to the Rectangle's height/implicitHeight. The rectangle just clips at the bottom, but never scrolls. (And the scrollbar still seems to do nothing)

    I updated the question to show what I've done. I feel like something basic is missing/wrong...just can't figure out what



  • I suspect that adding a scrollbar to a scrollview disconnects it from everything. I've read the docs, and although the don't explicitly say so, I think scrollView contains an inherint scrollbar. So add a new one:
    ScrollBar.vertical: ScrollBar {}

    cases a standlone scrollbar connected to nothing.


Log in to reply