# coding:utf-8 import sys from qtpy.QtCore import QRect, QSize, Qt from qtpy.QtGui import QColor, QPixmap, QIcon from qtpy.QtWidgets import QApplication, QLabel from QtFramelessWindow import FramelessWindow, TitleBar, 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) from qtpy import QT5 if QT5: QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) # run app app = QApplication(sys.argv) demo = Window() demo.show() sys.exit(app.exec_())