-
Notifications
You must be signed in to change notification settings - Fork 0
/
圆角窗口test.py
63 lines (53 loc) · 1.92 KB
/
圆角窗口test.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
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class RoundShadow(QWidget):
"""圆角边框类"""
def __init__(self, parent=None):
super(RoundShadow, self).__init__(parent)
self.border_width = 8
# 设置 窗口无边框和背景透明 *必须
self.setAttribute(Qt.WA_TranslucentBackground)
self.setWindowFlags(Qt.FramelessWindowHint | Qt.Window)
def paintEvent(self, event):
# 阴影
# path = QPainterPath()
# path.setFillRule(Qt.WindingFill)
# pat = QPainter(self)
# pat.setRenderHint(pat.Antialiasing)
# pat.fillPath(path, QBrush(Qt.white))
# color = QColor(192, 192, 192, 50)
# for i in range(10):
# i_path = QPainterPath()
# i_path.setFillRule(Qt.WindingFill)
# ref = QRectF(10 - i, 10 - i, self.width() - (10 - i) * 2, self.height() - (10 - i) * 2)
# # i_path.addRect(ref)
# i_path.addRoundedRect(ref, self.border_width, self.border_width)
# color.setAlpha(int(150 - i ** 0.5 * 50))
# pat.setPen(color)
# pat.drawPath(i_path)
# 圆角
pat2 = QPainter(self)
pat2.setRenderHint(pat2.Antialiasing) # 抗锯齿
pat2.setBrush(Qt.white)
pat2.setPen(Qt.transparent)
rect = self.rect()
rect.setLeft(9)
rect.setTop(9)
rect.setWidth(rect.width() - 9)
rect.setHeight(rect.height() - 9)
pat2.drawRoundedRect(rect, 4, 4)
class TestWindow(RoundShadow, QWidget):
"""测试窗口"""
def __init__(self, parent=None):
super(TestWindow, self).__init__(parent)
self.resize(300, 300)
def mouseReleaseEvent(self, e):
self.close()
if __name__ == '__main__':
app = QApplication(sys.argv)
t = TestWindow()
# t = RoundImage('./Asset/new_icons/close.png')
t.show()
app.exec_()