Qt 如何通过分别单击左右箭头将页面更改为SwipeView的下一项或上一项?

Qt 如何通过分别单击左右箭头将页面更改为SwipeView的下一项或上一项?,qt,qml,Qt,Qml,我有一个SwipeView,它通过中继器和加载器加载其内部元素 我想通过单击SwipeView左右两侧的箭头在项目之间向前和向后滑动。 如何在QML中实现此行为 SwipeView { id: __swipeView Layout.fillHeight: true Layout.fillWidth: true Repeater { model: 3

我有一个SwipeView,它通过中继器和加载器加载其内部元素

我想通过单击SwipeView左右两侧的箭头在项目之间向前和向后滑动。 如何在QML中实现此行为

SwipeView {
            id: __swipeView
            Layout.fillHeight: true
            Layout.fillWidth: true
            Repeater {
                model: 3
                Loader {
                    source: "qrc:/../SwipeDelegate.qml"
                }
            }
        }

在代理中,您可以通过访问
SwipeView
,然后根据需要增加或减少当前索引:

import QtQuick 2.6
import QtQuick.Controls 2.0

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    SwipeView {
        anchors.fill: parent

        Repeater {
            model: 3

            Item {
                id: delegate

                Button {
                    text: "<"
                    enabled: index > 0
                    onClicked: delegate.SwipeView.view.decrementCurrentIndex()
                    anchors.left: parent.left
                    anchors.verticalCenter: parent.verticalCenter
                }

                Label {
                    text: "Page " + (index + 1)
                    anchors.centerIn: parent
                }

                Button {
                    text: ">"
                    enabled: index < delegate.SwipeView.view.count - 1
                    onClicked: delegate.SwipeView.view.incrementCurrentIndex()
                    anchors.right: parent.right
                    anchors.verticalCenter: parent.verticalCenter
                }
            }
        }
    }
}
导入QtQuick 2.6
导入QtQuick.Controls 2.0
应用程序窗口{
可见:正确
宽度:640
身高:480
标题:qsTr(“你好世界”)
SwipeView{
锚定。填充:父级
中继器{
型号:3
项目{
id:代表
钮扣{
案文:“”
已启用:索引

与直接设置
currentIndex
相比,使用函数非常重要,原因如下。

最近有人问了一个类似的问题:好的,这个示例与我要查找的类似,只是我有SwipeView file.qml和另一个file.qml SwipeView委托,不能在委托中使用SwipeView方法