Qt Forum

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

    Solved ScrollView no scroll

    QML and Qt Quick
    2
    6
    172
    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.
    • S
      sandro4912 last edited by

      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 Reply Quote 0
      • B
        Bob64 @sandro4912 last edited by Bob64

        @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 Reply Quote 2
        • B
          Bob64 last edited by

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

          1 Reply Last reply Reply Quote 0
          • S
            sandro4912 last edited by 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 1 Reply Last reply Reply Quote 0
            • B
              Bob64 @sandro4912 last edited by Bob64

              @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 Reply Quote 1
              • S
                sandro4912 last edited by

                Yes correct I mean flickable.

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