gpt4 book ai didi

qt - QML:SwipeView 中项目的中间滑动位置

转载 作者:行者123 更新时间:2023-12-03 01:27:04 25 4
gpt4 key购买 nike

我正在尝试创建基于 SwipeView 元素的视差 View 。 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,但它会导致跳过项目而不是平滑过渡。

最佳答案

您无法控制水平 ListView 中项目的 x 坐标,因为项目位置由 ListView 管理。您之所以能够在第一个示例中操作项目位置,是因为您实际上并不是在操作委托(delegate)位置,而是在 Loader 委托(delegate)中包装了另一个项目。

对于 SwipeView 页面,除非您想使用类似的包装器,否则可以使用 Translate QML 类型应用转换。您可以通过 SwipeView.contentItem 访问 SwipeView 的内部 ListView 及其 contentX。计算所需的视差效果留给读者作为练习。 :)

PS。另请参阅 https://doc.qt.io/qt-5/qtquick-views-example.html 处的 ParallaxView 示例。 .

关于qt - QML:SwipeView 中项目的中间滑动位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40277351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com