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. ScrollView no scroll

ScrollView no scroll

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 438 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.
  • S Offline
    S Offline
    sandro4912
    wrote on last edited by
    #1

    Take the following code:

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    
    ScrollView {
        width: 200
        height: 200
    
        Rectangle{
            width: 1000
            height: 1000
    
            color: "red"
        }
    }
    
    

    I would have expected that since Rectangle is bigger than the View that I can scroll horizontally and vertically on default but it does not seem to happen.

    Can you tell me why?

    B 1 Reply Last reply
    0
    • S sandro4912

      Take the following code:

      import QtQuick 2.15
      import QtQuick.Controls 2.15
      
      ScrollView {
          width: 200
          height: 200
      
          Rectangle{
              width: 1000
              height: 1000
      
              color: "red"
          }
      }
      
      

      I would have expected that since Rectangle is bigger than the View that I can scroll horizontally and vertically on default but it does not seem to happen.

      Can you tell me why?

      B Offline
      B Offline
      Bob64
      wrote on last edited by Bob64
      #2

      @sandro4912 According to the documentation I think you either need explicitly to set contentHeight and contentWidth in your ScrollView to the Rectangle's height and width, or you need to set the implicitHeight and implicitWidth of the Rectangle to its height and width:

      contentHeight: real

      This property holds the height of the scrollable content.

      If only a single item is used within a ScrollView, the content size is automatically calculated based on the implicit size of its contained item.

      1 Reply Last reply
      2
      • B Offline
        B Offline
        Bob64
        wrote on last edited by
        #3

        Also, you probably want to set clip: true in your ScrollView.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sandro4912
          wrote on last edited by sandro4912
          #4

          I modified it like this:

          import QtQuick 2.15
          import QtQuick.Controls 2.15
          
          ScrollView {
              width: 200
              height: 200
              clip: true
              contentHeight: children.height
              contentWidth: children.width
          
              Rectangle{
                  width: 1000
                  height: 1000
                  implicitHeight: height
                  implicitWidth: width
          
                  color: "red"
              }
          }
          

          Now it works.

          Last Question. If I run this on a mobile device the view becomes flipable automatically?

          B 1 Reply Last reply
          0
          • S sandro4912

            I modified it like this:

            import QtQuick 2.15
            import QtQuick.Controls 2.15
            
            ScrollView {
                width: 200
                height: 200
                clip: true
                contentHeight: children.height
                contentWidth: children.width
            
                Rectangle{
                    width: 1000
                    height: 1000
                    implicitHeight: height
                    implicitWidth: width
            
                    color: "red"
                }
            }
            

            Now it works.

            Last Question. If I run this on a mobile device the view becomes flipable automatically?

            B Offline
            B Offline
            Bob64
            wrote on last edited by Bob64
            #5

            @sandro4912 sorry, I can't answer your last question as I do not do mobile development. If you meant flickable then I believe so but I am not sure.

            1 Reply Last reply
            1
            • S Offline
              S Offline
              sandro4912
              wrote on last edited by
              #6

              Yes correct I mean flickable.

              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