本文主要是介绍Qt/QML学习-Calendar,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
QML学习
- Calendar例程
- 视频讲解
- 代码
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.15Window {width: 640height: 480visible: truetitle: qsTr("Calendar")Calendar {id: the_calendaranchors.fill: parentstyle: CalendarStyle {// 顶部导航栏代理navigationBar: Rectangle {implicitHeight: 50// 底端黑线Rectangle {width: parent.widthheight: 2anchors.bottom: parent.bottomcolor: "black"}// 年份减少Rectangle {id: subYearwidth: parent.width * 0.15height: parent.height * 0.8anchors.verticalCenter: parent.verticalCenterText {anchors.centerIn: parenttext: "<<"font.bold: truefont.pointSize: 15MouseArea {anchors.fill: parenthoverEnabled: trueonEntered: {parent.color = "red"}onExited: {parent.color = "black"}onClicked: {control.showPreviousYear()}}}}// 年份Label {id: yearanchors.left: subYear.rightanchors.verticalCenter: parent.verticalCentertext: control.visibleYear+"年"font.bold: truefont.pointSize: 15}// 年份增加Rectangle {id: addYearwidth: parent.width * 0.15height: parent.height * 0.8anchors.left: year.rightanchors.verticalCenter: parent.verticalCenterText {anchors.centerIn: parenttext: ">>"font.bold: truefont.pointSize: 15MouseArea {anchors.fill: parenthoverEnabled: trueonEntered: {parent.color = "red"}onExited: {parent.color = "black"}onClicked: {control.showNextYear()}}}}// 月份增加Rectangle {id: addMonthwidth: parent.width * 0.15height: parent.height * 0.8anchors.verticalCenter: parent.verticalCenteranchors.right: parent.rightText {anchors.centerIn: parenttext: ">"font.bold: truefont.pointSize: 15MouseArea {anchors.fill: parenthoverEnabled: trueonEntered: {parent.color = "red"}onExited: {parent.color = "black"}onClicked: {control.showNextMonth()}}}}// 月份Label {id: monthanchors.right: addMonth.leftanchors.verticalCenter: parent.verticalCentertext: (control.visibleMonth+1)+"月"font.bold: truefont.pointSize: 15}// 月份减少Rectangle {id: subMonthwidth: parent.width * 0.15height: parent.height * 0.8anchors.verticalCenter: parent.verticalCenteranchors.right: month.leftText {anchors.centerIn: parenttext: "<"font.bold: truefont.pointSize: 15MouseArea {anchors.fill: parenthoverEnabled: trueonEntered: {parent.color = "red"}onExited: {parent.color = "black"}onClicked: {control.showPreviousMonth()}}}}}// 星期几代理dayOfWeekDelegate: Rectangle {implicitHeight: 40Label {anchors.centerIn: parenttext: control.__locale.dayName(styleData.dayOfWeek, control.dayOfWeekFormat)font.bold: truefont.pixelSize: 15}}// 日期代理dayDelegate: Rectangle {color: styleData.selected? "black": "white"Label {id: labelanchors.centerIn: parenttext: styleData.date.getDate()font.pointSize: 13color: styleData.selected? "white": "black"}}}//!onClicked: (date)=> {console.log(date)}}
}
演示
视频讲解
这篇关于Qt/QML学习-Calendar的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!