Skip to content

Commit 0f670c1

Browse files
committed
Add QmlCalendar
1 parent 5fa458e commit 0f670c1

File tree

7 files changed

+115
-0
lines changed

7 files changed

+115
-0
lines changed

QmlCalendar/QmlCalendar.pro

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#-------------------------------------------------
2+
#
3+
# Copyright (C) 2003-2103 CamelSoft Corporation
4+
#
5+
#-------------------------------------------------
6+
7+
QT += qml quick
8+
9+
CONFIG += c++11
10+
11+
SOURCES += main.cpp
12+
13+
RESOURCES += qml.qrc

QmlCalendar/main.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*!
2+
*@file main.cpp
3+
*@brief 程序主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
#include <QGuiApplication>
9+
#include <QQmlApplicationEngine>
10+
11+
int main(int argc, char *argv[])
12+
{
13+
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
14+
QGuiApplication app(argc, argv);
15+
16+
QQmlApplicationEngine engine;
17+
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
18+
19+
return app.exec();
20+
}

QmlCalendar/main.qml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*!
2+
*@file main.qml
3+
*@brief 主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
import QtQuick 2.7
9+
import QtQuick.Controls 1.4
10+
import QtQuick.Controls.Styles 1.4
11+
import QtQuick.Layouts 1.3
12+
13+
ApplicationWindow {
14+
visible: true
15+
width: 400
16+
height: 300
17+
title: qsTr("Qml日历")
18+
19+
function dayValid(date){
20+
var myArray = new Array();
21+
myArray[0]="13";
22+
myArray[1]="17";
23+
myArray[2]="26";
24+
25+
for(var i = 0; i < myArray.length;i++)
26+
{
27+
if (myArray[i] === date)
28+
{
29+
return(false);
30+
}
31+
}
32+
return(true);
33+
}
34+
35+
Calendar {
36+
anchors.centerIn: parent
37+
38+
style: CalendarStyle {
39+
gridVisible: false
40+
dayDelegate: Rectangle {
41+
property bool dayIsValid: dayValid(styleData.date.getDate().toString())
42+
43+
gradient: Gradient {
44+
GradientStop {
45+
position: 0.00
46+
color: styleData.selected && dayIsValid ? "#148014" : (styleData.visibleMonth && styleData.valid ? (dayIsValid ? "#CCCCCC" : "#FFFFFF") : "#FFFFFF");
47+
}
48+
}
49+
50+
Label {
51+
text: styleData.date.getDate()
52+
anchors.centerIn: parent
53+
}
54+
55+
Rectangle {
56+
width: parent.width
57+
height: 1
58+
color: "#EEEEEE"
59+
anchors.bottom: parent.bottom
60+
}
61+
62+
Rectangle {
63+
width: 1
64+
height: parent.height
65+
color: "#EEEEEE"
66+
anchors.right: parent.right
67+
}
68+
}
69+
}
70+
}
71+
}

QmlCalendar/qml.qrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>main.qml</file>
4+
</qresource>
5+
</RCC>

QmlCalendar/show.gif

35.9 KB
Loading

QtQuickExamples.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ SUBDIRS += QmlFlipImage
3232
SUBDIRS += QmlGrayImage
3333
SUBDIRS += QmlProgress
3434
SUBDIRS += QmlWinExtras
35+
SUBDIRS += QmlCalendar

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,8 @@ QmlWinExtras: QmlWinExtras
142142

143143
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlWinExtras/show.gif?raw=true)
144144

145+
146+
QmlCalendar:Qml日历
147+
148+
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlCalendar/show.gif?raw=true)
149+

0 commit comments

Comments
 (0)