-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathTestCTitleBar.py
115 lines (94 loc) · 2.66 KB
/
TestCTitleBar.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2019年7月15日
@author: Irony
@site: https://pyqt5.com https://github.com/892768447
@email: [email protected]
@file: TestCTitleBar
@description:
"""
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QDialog
from CustomWidgets.CTitleBar import CTitleBar
__Author__ = 'Irony'
__Copyright__ = 'Copyright (c) 2019'
class TestCTitleBarBase:
def __init__(self, *args, **kwargs):
super(TestCTitleBarBase, self).__init__(*args, **kwargs)
self.resize(500, 400)
# 设置背景透明
self.setAttribute(Qt.WA_TranslucentBackground, True)
# 设置无边框
self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
layout = QVBoxLayout(self)
layout.setSpacing(0)
# 添加自定义标题栏
layout.addWidget(CTitleBar(self, title='CTitleBar'))
# 底部空白占位
layout.addWidget(QWidget(self, objectName='bottomWidget'))
class TestCTitleBarWidget(QWidget, TestCTitleBarBase):
pass
class TestCTitleBarDialog(QDialog, TestCTitleBarBase):
pass
# 标题栏样式
Style = """
/*标题栏颜色*/
CTitleBar {
background: rgb(65, 148, 216);
}
/*标题栏圆角*/
CTitleBar {
border-top-right-radius: 10px;
border-top-left-radius: 10px;
}
#CTitleBar_buttonClose {
/*需要把右侧的关闭按钮考虑进去*/
border-top-right-radius: 10px;
}
/*底部圆角和背景*/
#bottomWidget {
background: white;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
}
/*最小化、最大化、还原按钮*/
CTitleBar > QPushButton {
background: transparent;
}
CTitleBar > QPushButton:hover {
background: rgba(0, 0, 0, 30);
}
CTitleBar > QPushButton:pressed {
background: rgba(0, 0, 0, 60);
}
/*关闭按钮*/
#CTitleBar_buttonClose:hover {
color: white;
background: rgb(232, 17, 35);
}
#CTitleBar_buttonClose:pressed {
color: white;
background: rgb(165, 69, 106);
}
"""
if __name__ == '__main__':
import sys
import cgitb
sys.excepthook = cgitb.enable(1, None, 5, '')
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
app.setStyleSheet(Style)
w = TestCTitleBarWidget()
w.show()
# 模态属性
w1 = TestCTitleBarDialog()
w1.setWindowTitle('对话框')
w1.show()
# 不可调整大小
w2 = TestCTitleBarWidget()
w2.setWindowTitle('不可调整大小')
w2.setMinimumSize(400, 400)
w2.setMaximumSize(400, 400)
w2.show()
sys.exit(app.exec_())