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?
-
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
andcontentWidth
in yourScrollView
to theRectangle
'sheight
andwidth
, or you need to set theimplicitHeight
andimplicitWidth
of theRectangle
to itsheight
andwidth
: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.
-
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?
-
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.