如何实现swipeview QtQuick 2.5

如何实现swipeview QtQuick 2.5,qt,qml,qtquickcontrols,qtquickcontrols2,Qt,Qml,Qtquickcontrols,Qtquickcontrols2,我有Qt5.5,它不支持SwipeView。我尝试使用listView,但没有达到预期效果。我希望在Qt5.5中有一个类似的功能代码,就像下面给出的代码一样,它是在Qt5.6中编写的。请帮忙 import QtQuick 2.6 import QtQuick.Controls 2.0 import QtQuick.Window 2.0 Window { visible: true width: 200 height: 400 title: qsTr("Hello

我有Qt5.5,它不支持SwipeView。我尝试使用listView,但没有达到预期效果。我希望在Qt5.5中有一个类似的功能代码,就像下面给出的代码一样,它是在Qt5.6中编写的。请帮忙

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++
            }
        }
    }


}
导入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.currentIndexQt快速控制2:

Qt Quick Controls 2提供了一组控件,可用于在Qt Quick中构建完整的接口。该模块在Qt 5.7中引入

Qt Labs控件是在Qt 5.6中引入的,因此您引用的代码必须使用
Qt.Labs.Controls 1.0
import才能与Qt 5.6一起运行


您需要使用较新的Qt版本(5.6或更高版本)。

如果无法更新Qt版本,您确实可以使用ListView、a和a来近似SwipeView

SwipeView.qml

ListView
{
id:根
//允许为QtQuick添加页面。控件2 SwipeView
//您在SwipeView中声明的每个项目都将重新租给itemModel
默认属性别名项:itemModel.children
//SwipeView是水平的
方向:Qt.水平
//隐藏越界页面
剪辑:对
//不要停在两页之间
snapMode:ListView.SnapToItem
//在浏览页面时更新currentIndex
highlightRangeMode:ListView.StrictlyEnforceRange
模型:Visualitemodel{
id:itemModel
//用于将页面大小绑定到swipeView大小
一旦儿童改变:{

对于(var i=0;i您是否尝试过tabview?我认为定制样式的tabview可以满足您的需要。