forked from PyQt5/PyQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalendarWidget.py
117 lines (100 loc) · 3.14 KB
/
CalendarWidget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
'''
Created on 2018年1月30日
@author: Irony."[讽刺]
@site: http://alyl.vip, http://orzorz.vip, https://coding.net/u/892768447, https://github.com/892768447
@email: [email protected]
@file: CalendarWidget
@description: 日历
'''
import sys
from PyQt5.QtWidgets import QApplication, QCalendarWidget
StyleSheet = '''
/*顶部导航区域*/
#qt_calendar_navigationbar {
background-color: rgb(0, 188, 212);
min-height: 100px;
}
/*上一个月按钮和下一个月按钮(从源码里找到的objectName)*/
#qt_calendar_prevmonth, #qt_calendar_nextmonth {
border: none; /*去掉边框*/
margin-top: 64px;
color: white;
min-width: 36px;
max-width: 36px;
min-height: 36px;
max-height: 36px;
border-radius: 18px; /*看来近似椭圆*/
font-weight: bold; /*字体加粗*/
qproperty-icon: none; /*去掉默认的方向键图片,当然也可以自定义*/
background-color: transparent;/*背景颜色透明*/
}
#qt_calendar_prevmonth {
qproperty-text: "<"; /*修改按钮的文字*/
}
#qt_calendar_nextmonth {
qproperty-text: ">";
}
#qt_calendar_prevmonth:hover, #qt_calendar_nextmonth:hover {
background-color: rgba(225, 225, 225, 100);
}
#qt_calendar_prevmonth:pressed, #qt_calendar_nextmonth:pressed {
background-color: rgba(235, 235, 235, 100);
}
/*年,月控件*/
#qt_calendar_yearbutton, #qt_calendar_monthbutton {
color: white;
margin: 18px;
min-width: 60px;
border-radius: 30px;
}
#qt_calendar_yearbutton:hover, #qt_calendar_monthbutton:hover {
background-color: rgba(225, 225, 225, 100);
}
#qt_calendar_yearbutton:pressed, #qt_calendar_monthbutton:pressed {
background-color: rgba(235, 235, 235, 100);
}
/*年份输入框*/
#qt_calendar_yearedit {
min-width: 50px;
color: white;
background: transparent;/*让输入框背景透明*/
}
#qt_calendar_yearedit::up-button { /*往上的按钮*/
width: 20px;
subcontrol-position: right;/*移动到右边*/
}
#qt_calendar_yearedit::down-button { /*往下的按钮*/
width: 20px;
subcontrol-position: left; /*移动到左边去*/
}
/*月份选择菜单*/
CalendarWidget QToolButton QMenu {
background-color: white;
}
CalendarWidget QToolButton QMenu::item {
padding: 10px;
}
CalendarWidget QToolButton QMenu::item:selected:enabled {
background-color: rgb(230, 230, 230);
}
CalendarWidget QToolButton::menu-indicator {
/*image: none;去掉月份选择下面的小箭头*/
subcontrol-position: right center;/*右边居中*/
}
/*下方的日历表格*/
#qt_calendar_calendarview {
outline: 0px;/*去掉选中后的虚线框*/
selection-background-color: rgb(0, 188, 212); /*选中背景颜色*/
}
'''
class CalendarWidget(QCalendarWidget):
def __init__(self, *args, **kwargs):
super(CalendarWidget, self).__init__(*args, **kwargs)
# 隐藏左边的序号
self.setVerticalHeaderFormat(self.NoVerticalHeader)
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setStyleSheet(StyleSheet)
w = CalendarWidget()
w.show()
sys.exit(app.exec_())