QML 完全模拟飞书日程界面(一)

QML完全模仿飞书日程界面(一)

首先先贴一个飞书的日程界面截图
https://img-blog.csdnimg.cn/5fc2430c45884636b971616a87b38bdd.png


然后再贴一个本期要模仿的部分

日程标题



前言

分为四个部分,今天这个复位按钮,切换日期按钮,显示当前年份月份日期的label,用于切换日月周的tabbar


一、复位按钮部分

复位按钮
代码如下:

    Button {
        id: _resetBtn
        anchors{
            top: parent.top
            topMargin: 16
            left: parent.left
            leftMargin: 16
        }
        width: 60
        height: 32
        background: Rectangle {
            color: parent.hovered ? "#DCDFE5" : _resetBtn.checked ? "white" : "#E8F2FF"
            border.width: 1
            border.color: "#1962FF"
            radius: 4
        }
        contentItem :Text {
            color: "#1962FF"
            anchors{
//                //!这样写是为了居中
                top: parent.top
                topMargin: 6
                left: parent.left
                leftMargin: 16

            }
            font.family: "PingFang SC"
            font.pixelSize: 14
            text: "今天"
            opacity: 1
        }
        onClicked: {
            _root.gotoToday()
        }
    }

二、切换日期按钮

切换日期按钮
代码如下:

    Rectangle{
        id: _lastAndNextMonthBtn
        color: "transparent"
        border.width: 1
        border.color: "#DCDFE5"
        anchors{
            top: parent.top
            topMargin: 16
            left: _resetBtn.right
            leftMargin: 12
        }
        radius: 4
        width: 65
        height: 32
        Button {
            text: "<"
            anchors{
                top: parent.top
                topMargin: 0
                left: parent.left
                leftMargin: 2
            }
            width: 32
            background: Rectangle {
                color: parent.hovered ? "#DCDFE5" : "#FFFFFF"
                anchors{
                    fill: parent
                    margins: 3
                    leftMargin: 0
                }
                radius: 4
            }
            font.family: "PingFang SC"
            font.pixelSize: 14
            onClicked: {
                _root.gotoLastMonth()
            }
        }
        Rectangle{
            color: "#DCDFE5"
            width: 1
            anchors{
                verticalCenter: parent.verticalCenter
                horizontalCenter: parent.horizontalCenter
            }
            height: parent.height - 8
        }
        Button {
            text: ">"
            anchors{
                top: parent.top
                topMargin: 0
                right: parent.right
                rightMargin: -1
            }
            width: 32
            background: Rectangle {
                color: parent.hovered ? "#DCDFE5" : "white"
                anchors{
                    fill: parent
                    margins: 3
                    leftMargin: 0
                }
                radius: 4
            }
            font.family: "PingFang SC"
            font.pixelSize: 14
            onClicked: {
                _root.gotoNextMonth()
            }
        }
    }

三、显示当前年份月份日期的label

当前日期的label

代码如下:

    Text {
        width: 92
        height: 23
        anchors{
            top: parent.top
            topMargin: 20
            left: _lastAndNextMonthBtn.right
            leftMargin: 12
        }
        verticalAlignment: Qt.AlignVCenter
        font.family: "PingFang SC"
        text: currentDate_Year + "年" + currentDate_Month + "月"
        renderType: Text.NativeRendering
        font.pixelSize: 20
        font.bold: false
        antialiasing: true
    }

暂且只写了年和月,后续会把日和今天都补充上


四、用于切换日月周的tabbar

在这里插入图片描述
代码如下:

Rectangle{
        width: 212
        height: 32
        anchors{
            top: parent.top
            topMargin: 16
            right: parent.right
            rightMargin: 16
        }
        border.color:  "#DCDFE5"
        border.width: 1
        radius: 6
        TabBar {
            id: _bar
            anchors.fill: parent
            anchors.margins: 1
            font.family: "PingFang SC"
            font.pixelSize: 14
            background: Rectangle {
                radius: 6
                color: "#FFFFFF"
            }

            Repeater {
                model: ["日", "周", "月"]

                TabButton {
                    text: modelData
                    contentItem: IconLabel {
                        text: parent.text
                        font: parent.font
                        color: parent.checked ? "#1962FF" : "#1F2329"
                    }
                    background: Rectangle{
                        radius: 4
                        anchors.fill: parent
                        anchors.margins: 3
                        anchors.bottomMargin: 5
                        color: parent.hovered ? "#DCDFE5" : parent.checked ? "#E8F2FF" : "#FFFFFF"
                    }
                }
            }
        }
    }

总结

先从最简单的开始,下一期模仿单天的日期显示如下:
单天的日期显示

—————————本文严禁转载—————————

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值