【Qt Quick】实现多任务滑动界面

效果展示

在这里插入图片描述

代码部分

BG.qml

import QtQuick 2.0
import QtQuick.Controls 2.5
/*
*主窗口背景
*/
Item {
    anchors.fill: parent
    Rectangle{
        id:rect_BG
        anchors.fill: parent
        radius: 5
        color: "#b5b5b5b5"
    }


    SwipeView{
        id:swipeView
        anchors.left: parent.left
        anchors.leftMargin: 10
        anchors.right: parent.right
        anchors.rightMargin: 10
        anchors.top: parent.top
        anchors.topMargin: 50
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 30

        spacing: 10

        ServerPanel{id:sp_ROOT}

        ListPanel{id:lp_ROOT}
    }

    PageIndicator{
        id:indicator
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 10
        anchors.horizontalCenter: parent.horizontalCenter

        currentIndex: swipeView.currentIndex
        count:swipeView.count
    }


}

ServerPanel.qml

第一个页面

import QtQuick 2.0
import QtQuick.Controls 2.5


Page {
    background: null
    Label{
        anchors.horizontalCenter: parent.hoverEnabled

        Text {
            text: "服务器界面"
            color: "white"
            font.bold: true
            font.pointSize: 14
        }
    }
}



ListPanel.qml

第二个页面

import QtQuick 2.0
import QtQuick.Controls 2.5
Page {
    id:lp_ROOT
    background: null
    Label{
        anchors.horizontalCenter: parent.hoverEnabled
        Text {
            text: "列表界面"
            color: "white"
            font.bold: true
            font.pointSize: 14
        }


    }
}

点击切换

SwipeView是通过更改currentIndex来实现切换页面的,所以只需要将你的SwipeView内的id声明出来然后修改currentIndex即可。

    Button{
        id:btn_Front
        text: "上一个"
        anchors.centerIn: parent
        onClicked: {
            bg_ROOT.swipeView.currentIndex -= 1
        }
    }

注意
1.Page是自带背景色的,默认为白色,如果想取消背景,使用background: null

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

非西昂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值