Python PyQT5 cancels the title bar and maximum change, minimize and close buttons

Python PyQT5 cancels the title bar and maximum change, minimize and close buttons

1. Operating environment

Operating system: Windows 10 Professional Edition, IDE: PyCharm 2020.2.3 (Community Edition), SDK: Python 3.7

2. Code and pictures

# Set the window flags and remove the title bar 
self.setWindowFlags(Qt.FramelessWindowHint)
# Remove the maximum change, minimize and close buttons 
self.setWindowFlags(Qt.WindowCloseButtonHint|Qt.WindowStaysOnTopHint|Qt.WindowCloseButtonHint)

Complete code

class BaseWidget(QWidget):
    def __init__(self):
        super().__init__()
        self.resize(1024, 600)
        self.setObjectName("MainWindow")
        self.setStyleSheet("#MainWindow{background-color:#00B7FD}")
        # 去掉最大变化、最小化及关闭按钮
        self.setWindowFlags(Qt.WindowCloseButtonHint|Qt.WindowStaysOnTopHint|Qt.WindowCloseButtonHint)
        # 设置窗口标志,去掉标题栏
        self.setWindowFlags(Qt.FramelessWindowHint)

renderings

Guess you like

Origin blog.csdn.net/zy0412326/article/details/135206536