I have code like this:
ScrollView {
Image {
source: "..."
}
}
Image
is higher than the ScrollView
. How can I scroll the latter to to center the Image
?
I have code like this:
ScrollView {
Image {
source: "..."
}
}
Image
is higher than the ScrollView
. How can I scroll the latter to to center the Image
?
Despite the appearence,
ScrollView
is tightly related toFlickable
. Indeed,Flickable
is used to control the visible area. Such anItem
is available as the (readonly
) propertyflickableItem
.Flickable
has thecontentX
andcontentY
properties to control the current visible area. These properties can be combined with thewidth
andheight
of theScrollView
to position the visible area exactly at the center. Typically you have:The difference is necessary since the first calls just moves the center to the top left point of the visible area (where
contentX
/contentY
are located).Here is a complete example with an
Image
as main child of theScrollView
.Disclaimer: In the simple scenario proposed by the example, with a remotelly loaded image, sizes can still be unset when
onCompleted
is called, resulting in a centering code that doesn't work. By setting widths and heigths directly into code the problem is avoided. In a real scenario such detail should be unnecessary.