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