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

ScrollView no scroll



  • 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?



  • @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.



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



  • 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?



  • @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.



  • Yes correct I mean flickable.


Log in to reply