QML_滑动导航模型SwipeView

QML_滑动导航模型SwipeView

SwipeView
属性:
horizontal : 保存滑动视图是否为水平
interactive : 描述用户是否可以与SwipeView进行交互,设置为true则用户无法滑动
orientation : 保留方向
vertical : 保存滑动视图是否垂直
附加属性:
index : 保存SwipeView中每个子项的索引
isCurrentItem : 若子项为当前项,则此属性为true
isNextItem : 若子项是下一个项目,则此属性为true
isPreviousItem : 若子项是上一个项目,则此属性为true
view : 包含管理此子项的视图

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.3

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("ColorDialog")

    SwipeView {
        id: view
        currentIndex: 1  //设置默认在的页数
        anchors.fill: parent
        orientation: Qt.Vertical  //设置滑动切换的方向
        interactive: true  //是否允许让滑动

        Rectangle {
            id: firstPage
            color: "purple"
            Text {
                text: qsTr("First")
                anchors.centerIn: parent
                font.pixelSize: 25
            }
        }
        Rectangle {
            id: secondPage
            color: "blue"
            Text {
                text: qsTr("Second")
                anchors.centerIn: parent
                font.pixelSize: 25
            }
        }
        Rectangle {
            id: thirdPage
            color: "green"
            Text {
                text: qsTr("Third")
                anchors.centerIn: parent
                font.pixelSize: 25
            }
        }
    }
}

在这里插入图片描述

建议大家在填充SwipeView的时候选择的是Page组件,Page是一个容器控件,可以方便地将页眉和页脚项添加到页面。它的三个重要属性footer、header、title分别对应着页脚、页眉和标题栏。因为我们的SwipeView本身是不可见的,需要为其设置指示才可以知道当前是第几页。通过page的属性我们可以设置指示栏
在这里插入图片描述

SwipeView {
    id: view
    currentIndex: 0
    anchors.fill: parent
    orientation: Qt.Vertical
    interactive: true

    Page {
        header: Rectangle {
            height: 80
            color: "orange"
            Text {
                anchors.centerIn: parent
                text: "one"
                font.pixelSize: 25
            }
        }

        footer: Rectangle {
            height: 30
            color: "orange"
        }
    }

    Page {
        header: Rectangle {
            height: 80
            color: "orange"
            Text {
                anchors.centerIn: parent
                text: "two"
                font.pixelSize: 25
            }
        }

        footer: Rectangle {
            height: 30
            color: "orange"
        }
    }
}

页面指示符PageIndicator

SwipeView {
    id: view
    currentIndex: pageIndicator.currentIndex
    anchors.fill: parent
    orientation: Qt.Horizontal
    interactive: true

    Rectangle {
        id: firstPage
        color: "purple"
        Text {
            text: qsTr("First")
            anchors.centerIn: parent
            font.pixelSize: 25
        }
    }
    Rectangle {
        id: secondPage
        color: "blue"
        Text {
            text: qsTr("Second")
            anchors.centerIn: parent
            font.pixelSize: 25
        }
    }
    Rectangle {
        id: thirdPage
        color: "green"
        Text {
            text: qsTr("Third")
            anchors.centerIn: parent
            font.pixelSize: 25
        }
    }
}

PageIndicator {
    id: pageIndicator
    interactive: true
    count: view.count
    currentIndex: view.currentIndex
    anchors.bottom: parent.bottom
    anchors.horizontalCenter: parent.horizontalCenter
}

在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值