0

0

QML2.0下的丰富的控件之日历

php中文网

php中文网

发布时间:2016-06-07 15:36:54

|

2606人浏览过

|

来源于php中文网

原创

Import Statement:span style=white-space:pre/span import QtQuick.Controls 1.2Since:span style=white-space:pre/span Qt 5.3Inherits:span style=white-space:pre/spanFocusScope PropertiesdayOfWeekFormat : intframeVisible : boolmaximumDate : date

Import Statement:	
import QtQuick.Controls 1.2
Since:	 Qt 5.3
Inherits:	
FocusScope
Properties

dayOfWeekFormat : int
frameVisible : bool
maximumDate : date
minimumDate : date
selectedDate : date
style : Component
visibleMonth : int
visibleYear : int
weekNumbersVisible : bool
Signals

clicked(date date)
doubleClicked(date date)
hovered(date date)
pressed(date date)
released(date date)
Methods

showNextMonth()
showNextYear()
showPreviousMonth()
showPreviousYear()

日历控件是基于qt5.x以上 需要导入qtquick.controls.1.2即可使用

日历控件主要使用到三个样式的设置

使用其中style:CalendarStyle

background : Component
control : Calendar
dayDelegate : Component
dayOfWeekDelegate : Component
gridColor : color
gridVisible : bool
navigationBar : Component
weekNumberDelegate : Component

其中dayDelegate主要设置日期的样式

dayOfWeekDelegate 主要设置周的样式

建站之星(sitestar)网站建设系统体验包2.3
建站之星(sitestar)网站建设系统体验包2.3

建站之星网站建设系统是一种全新的互联网应用模式,它一改过去传统的企业建站方式,不需企业编写任何程序或网页,无需学习任何相关语言,也不需第三方代写或管理网站,只需应用系统所提供的各种强大丰富的功能模块,即可轻松生成企业个性化的精美网站。 SiteStar v2.3本地软件体验包说明:为方便客户能够第一时间体验智能建站软件的强大功能,我们特别提供了本地软件体验包,您只需下载下来并安装在您的计算机上(和

下载

navigationBar 主要设置导航选择月份的样式

background 主要设置背景样式

下面看下例子是如何使用的

Calendar {
            id: calendar
            width: parent.width * 0.6 - row.spacing / 2
            height: parent.height
            selectedDate: new Date()
            focus: true

            style: CalendarStyle {
                dayDelegate: Rectangle {//设置日期样式,使用了渐变式
                    gradient: Gradient {
                        GradientStop {
                            position: 0.00
                            color: styleData.selected ? "#111" : (styleData.visibleMonth && styleData.valid ? "#444" : "#666");
                        }
                        GradientStop {
                            position: 1.00
                            color: styleData.selected ? "#444" : (styleData.visibleMonth && styleData.valid ? "#111" : "#666");
                        }
                        GradientStop {
                            position: 1.00
                            color: styleData.selected ? "#777" : (styleData.visibleMonth && styleData.valid ? "#111" : "#666");
                        }
                    }

                    Label {
                        text: styleData.date.getDate()
                        anchors.centerIn: parent
                        color: styleData.valid ? "white" : "grey"
                    }

                    Rectangle {
                        width: parent.width
                        height: 1
                        color: "#555"
                        anchors.bottom: parent.bottom
                    }

                    Rectangle {
                        width: 1
                        height: parent.height
                        color: "#555"
                        anchors.right: parent.right
                    }
                }
                dayOfWeekDelegate: Item{//设置周的样式
                    Rectangle{
                        anchors.fill: parent
                        Text {
                            id: weekTxt
                            text:Qt.locale().dayName(styleData.dayOfWeek, control.dayOfWeekFormat)//转换为自己想要的周的内容的表达
                            anchors.centerIn: parent
                            color: styleData.selected?"green":"gray"
                        }
                    }
                }
                navigationBar: Rectangle {//导航控制栏,控制日期上下选择等
                        color: "#49A9E3"
                        height: dateText.height * 4

                        Rectangle {
                            color: Qt.rgba(1, 1, 1, 0.6)
                            height: 1
                            width: parent.width
                        }

                        Rectangle {
                            anchors.bottom: parent.bottom
                            height: 1
                            width: parent.width
                            color: "#ddd"
                        }
                        ToolButton {
                            id: previousMonth
                            width: parent.height
                            height: width-20
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.left: parent.left
                            anchors.leftMargin: 40
                            iconSource: "qrc:/images/left.png"
                            onClicked: control.showPreviousMonth()
                        }
                        Label {
                            id: dateText
                            text: styleData.title
                            font.pixelSize: 14
                            font.bold: true
                            horizontalAlignment: Text.AlignHCenter
                            verticalAlignment: Text.AlignVCenter
                            fontSizeMode: Text.Fit
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.left: previousMonth.right
                            anchors.leftMargin: 2
                            anchors.right: nextMonth.left
                            anchors.rightMargin: 2
                        }
                        ToolButton {
                            id: nextMonth
                            width: 60
                            height: 53
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.right: parent.right
                            anchors.rightMargin: 40
                            iconSource: "qrc:/images/right.png"
                            onClicked: control.showNextMonth()
                            style: ButtonStyle {
                                    background: Item {
                                        implicitWidth: 25
                                        implicitHeight: 25
                                    }
                                }
                        }
                    }
            }
        }
日历控件差不多就这些样式需要设置,具体可以多参考Qt的帮助文档

相关专题

更多
C++ 高级模板编程与元编程
C++ 高级模板编程与元编程

本专题深入讲解 C++ 中的高级模板编程与元编程技术,涵盖模板特化、SFINAE、模板递归、类型萃取、编译时常量与计算、C++17 的折叠表达式与变长模板参数等。通过多个实际示例,帮助开发者掌握 如何利用 C++ 模板机制编写高效、可扩展的通用代码,并提升代码的灵活性与性能。

10

2026.01.23

php远程文件教程合集
php远程文件教程合集

本专题整合了php远程文件相关教程,阅读专题下面的文章了解更多详细内容。

29

2026.01.22

PHP后端开发相关内容汇总
PHP后端开发相关内容汇总

本专题整合了PHP后端开发相关内容,阅读专题下面的文章了解更多详细内容。

21

2026.01.22

php会话教程合集
php会话教程合集

本专题整合了php会话教程相关合集,阅读专题下面的文章了解更多详细内容。

21

2026.01.22

宝塔PHP8.4相关教程汇总
宝塔PHP8.4相关教程汇总

本专题整合了宝塔PHP8.4相关教程,阅读专题下面的文章了解更多详细内容。

13

2026.01.22

PHP特殊符号教程合集
PHP特殊符号教程合集

本专题整合了PHP特殊符号相关处理方法,阅读专题下面的文章了解更多详细内容。

11

2026.01.22

PHP探针相关教程合集
PHP探针相关教程合集

本专题整合了PHP探针相关教程,阅读专题下面的文章了解更多详细内容。

8

2026.01.22

菜鸟裹裹入口以及教程汇总
菜鸟裹裹入口以及教程汇总

本专题整合了菜鸟裹裹入口地址及教程分享,阅读专题下面的文章了解更多详细内容。

55

2026.01.22

Golang 性能分析与pprof调优实战
Golang 性能分析与pprof调优实战

本专题系统讲解 Golang 应用的性能分析与调优方法,重点覆盖 pprof 的使用方式,包括 CPU、内存、阻塞与 goroutine 分析,火焰图解读,常见性能瓶颈定位思路,以及在真实项目中进行针对性优化的实践技巧。通过案例讲解,帮助开发者掌握 用数据驱动的方式持续提升 Go 程序性能与稳定性。

9

2026.01.22

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Bootstrap 5教程
Bootstrap 5教程

共46课时 | 3万人学习

【web前端】Node.js快速入门
【web前端】Node.js快速入门

共16课时 | 2万人学习

国外Web开发全栈课程全集
国外Web开发全栈课程全集

共12课时 | 1.0万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号