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. Can't scroll content of a ScrollView
QtWS25 Last Chance

Can't scroll content of a ScrollView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 327 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.
  • ocgltdO Offline
    ocgltdO Offline
    ocgltd
    wrote on last edited by ocgltd
    #1

    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.HilkJ 1 Reply Last reply
    0
    • ocgltdO 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.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @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


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

      1 Reply Last reply
      0
      • ocgltdO Offline
        ocgltdO Offline
        ocgltd
        wrote on last edited by ocgltd
        #3

        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

        ocgltdO 1 Reply Last reply
        0
        • ocgltdO 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

          ocgltdO Offline
          ocgltdO Offline
          ocgltd
          wrote on last edited by
          #4

          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
          0

          • Login

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