forked from PyQt5/PyQt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FramelessWindow.py
74 lines (62 loc) · 1.79 KB
/
FramelessWindow.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QTextEdit
from Lib.FramelessWindow import FramelessWindow # @UnresolvedImport
# Created on 2018年4月30日
# author: Irony
# site: https://pyqt5.com , https://github.com/892768447
# email: [email protected]
# file: Test
# description:
__Author__ = """By: Irony
QQ: 892768447
Email: [email protected]"""
__Copyright__ = 'Copyright (c) 2018 Irony'
__Version__ = 1.0
class MainWindow(QWidget):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
layout = QVBoxLayout(self, spacing=0)
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(QPushButton('按钮', self))
layout.addWidget(QTextEdit(self))
# 样式
StyleSheet = """
/*标题栏*/
TitleBar {
background-color: rgb(54, 157, 180);
}
/*最小化最大化关闭按钮通用默认背景*/
#buttonMinimum,#buttonMaximum,#buttonClose {
border: none;
background-color: rgb(54, 157, 180);
}
/*悬停*/
#buttonMinimum:hover,#buttonMaximum:hover {
background-color: rgb(48, 141, 162);
}
#buttonClose:hover {
color: white;
background-color: rgb(232, 17, 35);
}
/*鼠标按下不放*/
#buttonMinimum:pressed,#buttonMaximum:pressed {
background-color: rgb(44, 125, 144);
}
#buttonClose:pressed {
color: white;
background-color: rgb(161, 73, 92);
}
"""
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
app.setStyleSheet(StyleSheet)
w = FramelessWindow()
w.setWindowTitle('测试标题栏')
w.setWindowIcon(QIcon('Data/Qt.ico'))
w.setWidget(MainWindow(w)) # 把自己的窗口添加进来
w.show()
sys.exit(app.exec_())