首页 > 其他分享 >Qt/QML学习-Calendar

Qt/QML学习-Calendar

时间:2024-09-01 15:50:17浏览次数:6  
标签:anchors parent verticalCenter height width QML Calendar font Qt

QML学习

main.qml

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Controls 2.15

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

    Calendar {
        id: the_calendar
        anchors.fill: parent
        style: CalendarStyle {
            // 顶部导航栏代理
            navigationBar: Rectangle {
                implicitHeight: 50
                // 底端黑线
                Rectangle {
                    width: parent.width
                    height: 2
                    anchors.bottom: parent.bottom
                    color: "black"
                }
                // 年份减少
                Rectangle {
                    id: subYear
                    width: parent.width * 0.15
                    height: parent.height * 0.8
                    anchors.verticalCenter: parent.verticalCenter
                    Text {
                        anchors.centerIn: parent
                        text: "<<"
                        font.bold: true
                        font.pointSize: 15
                        MouseArea {
                            anchors.fill: parent
                            hoverEnabled: true
                            onEntered: {
                                parent.color = "red"
                            }
                            onExited: {
                                parent.color = "black"
                            }
                            onClicked: {
                                control.showPreviousYear()
                            }
                        }
                    }
                }
                // 年份
                Label {
                    id: year
                    anchors.left: subYear.right
                    anchors.verticalCenter: parent.verticalCenter
                    text: control.visibleYear+"年"
                    font.bold: true
                    font.pointSize: 15
                }
                // 年份增加
                Rectangle {
                    id: addYear
                    width: parent.width * 0.15
                    height: parent.height * 0.8
                    anchors.left: year.right
                    anchors.verticalCenter: parent.verticalCenter
                    Text {
                        anchors.centerIn: parent
                        text: ">>"
                        font.bold: true
                        font.pointSize: 15
                        MouseArea {
                            anchors.fill: parent
                            hoverEnabled: true
                            onEntered: {
                                parent.color = "red"
                            }
                            onExited: {
                                parent.color = "black"
                            }
                            onClicked: {
                                control.showNextYear()
                            }
                        }
                    }
                }
                // 月份增加
                Rectangle {
                    id: addMonth
                    width: parent.width * 0.15
                    height: parent.height * 0.8
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: parent.right
                    Text {
                        anchors.centerIn: parent
                        text: ">"
                        font.bold: true
                        font.pointSize: 15
                        MouseArea {
                            anchors.fill: parent
                            hoverEnabled: true
                            onEntered: {
                                parent.color = "red"
                            }
                            onExited: {
                                parent.color = "black"
                            }
                            onClicked: {
                                control.showNextMonth()
                            }
                        }
                    }
                }
                // 月份
                Label {
                    id: month
                    anchors.right: addMonth.left
                    anchors.verticalCenter: parent.verticalCenter
                    text: (control.visibleMonth+1)+"月"
                    font.bold: true
                    font.pointSize: 15
                }
                // 月份减少
                Rectangle {
                    id: subMonth
                    width: parent.width * 0.15
                    height: parent.height * 0.8
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: month.left
                    Text {
                        anchors.centerIn: parent
                        text: "<"
                        font.bold: true
                        font.pointSize: 15
                        MouseArea {
                            anchors.fill: parent
                            hoverEnabled: true
                            onEntered: {
                                parent.color = "red"
                            }
                            onExited: {
                                parent.color = "black"
                            }
                            onClicked: {
                                control.showPreviousMonth()
                            }
                        }
                    }
                }
            }
            // 星期几代理
            dayOfWeekDelegate: Rectangle {
                implicitHeight: 40
                Label {
                    anchors.centerIn: parent
                    text: control.__locale.dayName(styleData.dayOfWeek, control.dayOfWeekFormat)
                    font.bold: true
                    font.pixelSize: 15
                }
            }
            // 日期代理
            dayDelegate: Rectangle {
                color: styleData.selected? "black": "white"
                Label {
                    id: label
                    anchors.centerIn: parent
                    text: styleData.date.getDate()
                    font.pointSize: 13
                    color: styleData.selected? "white": "black"
                }
            }
        }
        //!
        onClicked: (date)=> {
                       console.log(date)
                   }
    }
}

演示

视频讲解

标签:anchors,parent,verticalCenter,height,width,QML,Calendar,font,Qt
From: https://blog.csdn.net/qq1138345424/article/details/141763480

相关文章

  • buildroot linux 添加QT自动启动桌面
    /etc/init.d/S99QTDesktop#!/bin/sh##Start/stopQTdesktop#exportXDG_RUNTIME_DIR=/usr/qt-armhf/lib#配置tslibexportTSLIB_TSDEVICE=/dev/input/event1exportTSLIB_CALIBFILE=/etc/pointercalexportTSLIB_CONFFILE=/etc/ts.confexportTSLIB_PLUGINDIR=/usr/lib/tse......
  • Qt模态对话框与非模态对话框
    前言在Qt中,模态对话框和非模态对话框是两种常见的对话框类型,它们的主要区别在于用户与应用程序的交互方式。正文对话框就是指QDialog嘛。模态对话框(ModalDialog)定义:模态对话框是指在弹出对话框期间,用户无法与应用程序的其他部分进行交互。用户必须先处理完对话......
  • C++创建GUI按钮\文本框(Windows)不用QT!!!
    一定要的:#include<windows.h>剩下的: 过程:LRESULTCALLBACKWndProc(HWNDhwnd,UINTMessage,WPARAMwParam,LPARAMlParam){switch(Message){ caseWM_CREATE:{ /*略*///HWND名称=CreateWindow(类型,显示的字,WS_CHILD|WS_VISIBLE,x,y,宽,......
  • 【Qt】Spacer
    Spacer在使用布局管理的时候,如果需要在控件之间添加一段空白,就可以使用QSpacerItem来表示。核心属性属性说明width宽度height⾼度hData⽔平⽅向的sizePolicyQSizePolicy::Ignored:忽略控件的尺⼨,不对布局产⽣影响。QSizePolicy::Minimum:......
  • Qt QString(十六进制形式) 转 int
    QString与QByteArray互转QStringstr("HelloWorld");QByteArraybytes=str.toUtf8();//QString转QByteArray方法1QStringstr("HelloWorld");QByteArraybytes=str.toLatin1();//QString转QByteArray方法2QByteArray转QStringQByteArraybytes(&......
  • Buildroot构建Qt根文件系统-思维导图-学习笔记-基于正点原子阿尔法开发板
    Buildroot构建Qt根文件系统获取Buildroot源码Buildroot源码下载地址,https://buildroot.org/本次下载的是长期支持版本移动至ubuntu后解压tarxfbuildroot-2022.02.3.tar.gz解压后的Buildroot源码配置Buildroot安装显示图形菜单需要的库sudoapt-getin......
  • Qt/C++地址转坐标/坐标转地址/逆地址解析/支持百度高德腾讯和天地图
    一、前言说明地址和经纬度坐标转换的功能必须在线使用,一般用在导航需求上,比如用户输入起点地址和终点地址,查询路线后,显示对应的路线,而实际上各大地图厂家默认支持的是给定经纬度坐标来查询(百度地图支持传入地址),但是你让用户输入经纬度坐标是不可能的,他肯定不可能知道怎么去拿到这......
  • 【python】PyQt5中富文本框QTextEdit的详细教程与应用实战
    ✨✨欢迎大家来到景天科技苑✨✨......
  • 【Qt】表单布局QFormLayout
     表单布局QFormLayoutQt还提供了QFormLayout,属于是QGridLayout的特殊情况,专⻔⽤于实现两列表单的布局.这种表单布局多⽤于让⽤⼾填写信息的场景.左侧列为提⽰,右侧列为输⼊框例子:使用QFormLayout创建表单(1)设置三个label、三个lineEdit(2)设置表单布局,将上述......
  • 我的第一个QT程序_创建项目_全程图解
    创建项目1.打开QT开发工具2.点【创建项目】在弹出的窗口的项目列表中选择【Application(Qt)】中间列选择第一项如上图。3.输入项目名称和项目保存的路径4.Buildsystem下拉列表中有三个选项,虽然Qt6主推CMake,所以可以默认,直接下一步5.类相关信息设置。这里也可以......