我正在尝试基于 SwipeView 元素创建视差视图。QML 文档中的示例说明了如何使用 ListView 实现它:
Image {
id: background
source: "background.png"
fillMode: Image.TileHorizontally
x: -list.contentX / 2
width: Math.max(list.contentWidth, parent.width)
}
ListView {
id: list
anchors.fill: parent
spacing: 20
snapMode: ListView.SnapToItem
orientation: ListView.Horizontal
highlightRangeMode: ListView.StrictlyEnforceRange
boundsBehavior: Flickable.StopAtBounds
maximumFlickVelocity: 1000
model: _some_cpp_list
//Loader is used as a workaround for QTBUG-49224
delegate: Loader {
id: loaderDelegate
source: "MyDelegate.qml"
width: myScreen.width
height: myScreen.height
onLoaded: {
loaderDelegate.item.logic = modelData
}
}
}
现在,这可行,但我想使用 SwipeView,而不是 ListView,因为它需要更少的代码来实现我想要的行为:
SwipeView {
id: list
anchors.fill: parent
spacing: 20
Repeater {
model: _some_cpp_list
delegate: MyDelegate {
logic: modelData
}
}
有什么方法可以访问 SwipeView 的当前“x”位置或滑动偏移以在此行中使用:
x: -list.contentX / 2
?
到目前为止我发现的最接近的是x: -swipeView.contentData[0].x / 2
,但它会导致跳过项目而不是平滑过渡。