如何在QML swipeview中实现翻页器按钮

如何在QML swipeview中实现翻页器按钮,qml,qtquick2,swipeview,qtquickcontrols2,Qml,Qtquick2,Swipeview,Qtquickcontrols2,我必须在SwipeView中使用QML组件来实现页面,比如Item(比如Item 1、Item 2、Item 3),而不使用中继器,还必须实现页面转换器,如下所示。getPreviousPage矩形应该将视图移动到上一页,类似于getNextPage矩形 import QtQuick 2.6 import QtQuick.Window 2.2 import QtQuick.Controls 2.0 Window { visible: true color:"black" width

我必须在SwipeView中使用QML组件来实现页面,比如Item(比如Item 1、Item 2、Item 3),而不使用中继器,还必须实现页面转换器,如下所示。getPreviousPage矩形应该将视图移动到上一页,类似于getNextPage矩形

import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 2.0

Window {
  visible: true
  color:"black"
  width: 400+100
  height: 200

  Rectangle
  {
      id:getPreviousPage
      color:"red"
      x:0
      y:0
      width:50
      height:200
      MouseArea
      {
          anchors.fill:parent
          onClicked:
          {
              //turn to previous page
          }
      }
  }

  Rectangle
  {
      id:getNextPage
      color:"green"
      width:50
      x:450
      y:0
      height:200
      MouseArea
      {
          anchors.fill:parent
          onClicked:
          {
              //turn to next page
          }
      }
  }




  Pane {
      id: pane
      width: 400
      height: 200
      x:50
      y:0

      SwipeView {
          id: view
          currentIndex: 1
          anchors.fill: parent

          Repeater {
              model: 3

              Pane {
                  width: view.width
                  height: view.height

                  Column {
                      spacing: 40
                      width: parent.width

                      Label {
                          width: parent.width
                          wrapMode: Label.Wrap
                          horizontalAlignment: Qt.AlignHCenter
                          text: view.currentIndex
                      }


                  }
              }
          }
      }


  }
    }
导入QtQuick 2.6
导入QtQuick.Controls 2.0
导入QtQuick.Window 2.0
窗口{
可见:正确
宽度:200
身高:400
标题:qsTr(“你好世界”)
id:第页
SwipeView{
id:swipeView
锚定。填充:父级
当前索引:0
页面{
标签{
正文:qsTr(“首页”)
anchors.centerIn:父对象
}
}
页面{
标签{
正文:qsTr(“第二页”)
anchors.centerIn:父对象
}
}
页面{
标签{
正文:qsTr(“第三页”)
anchors.centerIn:父对象
}
}
页面{
标签{
正文:qsTr(“第四页”)
anchors.centerIn:父对象
}
}
页面{
标签{
正文:qsTr(“第五页”)
anchors.centerIn:父对象
}
}
}
矩形
{
id:负号
宽度:parent.width/2
身高:100
锚。左:父。左
锚。底部:parent.bottom
颜色:“红色”
鼠耳
{
锚。填充:父
再次点击:{
如果(swipeView.currentIndex>0)
swipeView.currentIndex--
}
}
}
矩形
{
身份证号码:加
宽度:parent.width/2
身高:100
锚。右:父。右
锚。底部:parent.bottom
颜色:“绿色”
鼠耳
{
锚。填充:父
再次点击:{
如果(swipeView.currentIndexSince Qt Quick Controls 2.1(Qt 5.8))为方便起见(并避免破坏现有绑定),swipeView还具有递增的CurrentIndex()和递减的CurrentIndex()。
import QtQuick 2.6
import QtQuick.Controls 2.0
import QtQuick.Window 2.0
Window {
    visible: true
    width: 200
    height: 400
    title: qsTr("Hello World")

    id: page

    SwipeView {
        id: swipeView
        anchors.fill: parent
        currentIndex: 0
        Page {
                    Label {
                        text: qsTr("First page")
                        anchors.centerIn: parent
                    }
                }
        Page {
                    Label {
                        text: qsTr("Second page")
                        anchors.centerIn: parent
                    }
                }
        Page {
                    Label {
                        text: qsTr("Third page")
                        anchors.centerIn: parent
                    }
                }
        Page {
                    Label {
                        text: qsTr("Fourth page")
                        anchors.centerIn: parent
                    }
                }
        Page {
                    Label {
                        text: qsTr("Fifth page")
                        anchors.centerIn: parent
                    }
                }
    }



    Rectangle
    {
        id:minus
        width:parent.width/2
        height:100
        anchors.left:parent.left
        anchors.bottom:parent.bottom
        color:"red"
        MouseArea
        {
            anchors.fill:parent
            onClicked:{
                if(swipeView.currentIndex>0)
                    swipeView.currentIndex--
            }
        }
    }
    Rectangle
    {
        id:plus
        width:parent.width/2
        height:100
        anchors.right:parent.right
        anchors.bottom:parent.bottom
        color:"green"
        MouseArea
        {
            anchors.fill:parent
            onClicked:{
                if(swipeView.currentIndex<4)
                    swipeView.currentIndex++
            }
        }
    }


}