-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
demo.py
90 lines (70 loc) · 2.8 KB
/
demo.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
# coding:utf-8
import sys
from PyQt5.QtCore import QRect, QSize, Qt
from PyQt5.QtGui import QColor, QPixmap, QIcon
from PyQt5.QtWidgets import QApplication, QLabel
from qframelesswindow import FramelessWindow, StandardTitleBar
class CustomTitleBar(StandardTitleBar):
""" Custom title bar """
def __init__(self, parent):
super().__init__(parent)
# customize the style of title bar button
self.minBtn.setHoverColor(Qt.white)
self.minBtn.setHoverBackgroundColor(QColor(0, 100, 182))
self.minBtn.setPressedColor(Qt.white)
self.minBtn.setPressedBackgroundColor(QColor(54, 57, 65))
# use qss to customize title bar button
self.maxBtn.setStyleSheet("""
TitleBarButton {
qproperty-hoverColor: white;
qproperty-hoverBackgroundColor: rgb(0, 100, 182);
qproperty-pressedColor: white;
qproperty-pressedBackgroundColor: rgb(54, 57, 65);
}
""")
class Window(FramelessWindow):
def __init__(self, parent=None):
super().__init__(parent=parent)
# change the default title bar if you like
self.setTitleBar(CustomTitleBar(self))
self.label = QLabel(self)
self.label.setScaledContents(True)
self.label.setPixmap(QPixmap("screenshot/shoko.png"))
self.setWindowIcon(QIcon("screenshot/logo.png"))
self.setWindowTitle("PyQt-Frameless-Window")
self.setStyleSheet("background:white")
self.titleBar.raise_()
# customize the area of system title bar button, only works for macOS
if sys.platform == "darwin":
self.setSystemTitleBarButtonVisible(True)
self.titleBar.minBtn.hide()
self.titleBar.maxBtn.hide()
self.titleBar.closeBtn.hide()
def resizeEvent(self, e):
# don't forget to call the resizeEvent() of super class
super().resizeEvent(e)
length = min(self.width(), self.height())
self.label.resize(length, length)
self.label.move(
self.width() // 2 - length // 2,
self.height() // 2 - length // 2
)
def systemTitleBarRect(self, size: QSize) -> QRect:
""" Returns the system title bar rect, only works for macOS
Parameters
----------
size: QSize
original system title bar rect
"""
return QRect(size.width() - 75, 0, 75, size.height())
if __name__ == "__main__":
# enable dpi scale
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
# run app
app = QApplication(sys.argv)
demo = Window()
demo.show()
sys.exit(app.exec_())