Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Can't scroll content of a ScrollView

    QML and Qt Quick
    2
    4
    156
    Loading More Posts
    • 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.
    • ocgltd
      ocgltd last edited by ocgltd

      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.

      J.Hilk 1 Reply Last reply Reply Quote 0
      • J.Hilk
        J.Hilk Moderators @ocgltd last edited by

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

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

        Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply Reply Quote 0
        • ocgltd
          ocgltd last edited by ocgltd

          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

          ocgltd 1 Reply Last reply Reply Quote 0
          • ocgltd
            ocgltd @ocgltd last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post