Confusing ScrollView in Qt.Quick.Controls2
-
// Qt 5.15.2 import QtQuick 2.15 import QtQuick.Controls 2.15 ScrollView { id: scrollView function scrollToY(y) { scrollView.contentItem.contentY = y scrollView.contentItem.returnToBounds() // this works } contentItem.boundsBehavior: Flickable.StopAtBounds // Cannot assign to non-existent property "boundsBehavior" Pane { // ... // my contents is in this Pane // ... } }Above code is where I lost.
In ScrollView QML Type docs, there is NO description that what type thecontentItemis. List of All Members for ScrollView docs saidcontentItemis the member inherited fromControl, and the type isItem. But mycontentItemabove code hasreturnToBounds()method and it works!!
So I assumed that thecontentItem's type is maybeFlickable, cause the only type which hasreturnToBounds()isFlickable, and expect that it also hasboundsBehaviorproperty. But it doesnt.
I'm soooo confused. Why the document has no full description aboutcontentIteminScrollView? What the heck is realcontentItem? -
// Qt 5.15.2 import QtQuick 2.15 import QtQuick.Controls 2.15 ScrollView { id: scrollView function scrollToY(y) { scrollView.contentItem.contentY = y scrollView.contentItem.returnToBounds() // this works } contentItem.boundsBehavior: Flickable.StopAtBounds // Cannot assign to non-existent property "boundsBehavior" Pane { // ... // my contents is in this Pane // ... } }Above code is where I lost.
In ScrollView QML Type docs, there is NO description that what type thecontentItemis. List of All Members for ScrollView docs saidcontentItemis the member inherited fromControl, and the type isItem. But mycontentItemabove code hasreturnToBounds()method and it works!!
So I assumed that thecontentItem's type is maybeFlickable, cause the only type which hasreturnToBounds()isFlickable, and expect that it also hasboundsBehaviorproperty. But it doesnt.
I'm soooo confused. Why the document has no full description aboutcontentIteminScrollView? What the heck is realcontentItem?As far as the QML engine knows, it's an
Item. That's why you can't docontentItem.boundsBehavior: Flickable.StopAtBounds. Left-hand expressions have to fully typed and can't dynamically adapt. Right-hand expressions or Javascript expressions can, that's why you can callreturnToBounds()in your function.contentItemis in fact aFlickablebut you can use this fact for a declarative binding on it.
Most background areRectanglebut they are declared asItemand since you could change it to be a simple Item or any of its subclasses you can't dobackground.radius: 8but you can dobackground.visible: falsebecausevisibleis a property fromItem.In you case you could set the
boundsBehaviourin aComponent.onCompletedhandler or with aBinding:Binding { target: scrollView.contentItem property: "boundsBehaviour" value: Flickable.StopAtBounds }