S
setMask It's all broken.Here's what you need:self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
Read: https://doc.qt.io/qt-5/qt.html#WindowType-enum https://doc.qt.io/qt-5/qt.html#WidgetAttribute-enum I noted the lines that have changed.
Set your colors and images.Pay attention to the method. expand_windowand the other methods I've added.import sys
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.Qt import *
class Window(QWidget):
def init(self, parent=None):
super(Window, self).init(parent)
??? self.clicks = 0
self.setStyleSheet("background-color: rgb(235, 43, 50);")
self.setMinimumSize(800, 500)
self.setWindowFlags(Qt.FramelessWindowHint) # +++ !!!
self.setAttribute(Qt.WA_TranslucentBackground) # +++ !!!
self.offset = None # +++
''' вот это все ломает
path = QtGui.QPainterPath()
path.addRoundedRect(QtCore.QRectF(self.rect()), 10.0, 10.0)
mask = QtGui.QRegion(path.toFillPolygon().toPolygon())
self.setMask(mask)
'''
self.top_bar = QFrame()
self.top_bar.setObjectName('top_bar') # +++
self.top_bar.setStyleSheet("""
#top_bar { /* <---- */
background-color: rgb(35,43,150);
border-top-left-radius: 1em 1em; /* <---- */
border-top-right-radius: 1em 1em; /* <---- */
}
""")
self.top_bar.setMaximumHeight(40)
self.top_bar.setFrameShadow(QFrame.Raised)
self.content = QFrame()
self.content.setStyleSheet("""
background-color: rgb(135, 43, 50);
border-bottom-right-radius: 1em 1em; /* <---- */
border-bottom-left-radius: 1em 1em; /* <---- */
""")
self.content.setFrameShadow(QFrame.Raised)
# title_bar
self.title_bar = QFrame()
self.title_bar.setStyleSheet("""
background-color: #FFA41B;
border-top-left-radius: 1em 1em; /* <---- */
""")
self.title_bar.setMinimumWidth(120)
# min_button
self.min_button = QPushButton()
self.min_button.setStyleSheet("""
QPushButton:hover {
background-color: rgb(20,120,60);
border: 0px solid
}
QPushButton:!hover {
background-color: transparent;
border: 0px solid;
font: 11pt;
color: rgb(180,180,180)
}
""")
self.min_button.setIcon(
QIcon(QPixmap('minus.svg'))) # !
self.min_button.setMinimumHeight(40)
self.min_button.setMaximumWidth(40)
self.min_button.clicked.connect(self.turn_window)
# max_button
self.max_button = QPushButton()
self.max_button.setStyleSheet("""
QPushButton:hover {
background-color: rgb(20,120,60);
border: 0px solid
}
QPushButton:!hover {
background-color: transparent;
border: 0px solid;
font: 11pt;
color: rgb(180,180,180)
}
""")
self.max_button.setIcon(
QIcon(QPixmap('maximize.svg'))) # !
self.max_button.setMinimumHeight(40)
self.max_button.setMaximumWidth(40)
self.max_button.clicked.connect(self.expand_window)
# close_button
self.close_button = QPushButton()
self.close_button.setStyleSheet("""
QPushButton:hover {
background-color: rgb(20, 120, 60);
border: 0px solid;
border-top-right-radius: 1em 1em; /* <---- */
}
QPushButton:!hover {
background-color: transparent;
border: 0px solid;
font: 11pt;
color: rgb(180,180,180)
}
""")
self.close_button.setIcon(
QIcon(QPixmap('close.svg'))) # !
self.close_button.setMinimumHeight(40)
self.close_button.setMaximumWidth(40)
self.close_button.clicked.connect(self.close_window)
self.layout_navigation = QGridLayout(self.top_bar)
self.layout_navigation.addWidget(self.title_bar, 0, 0)
self.layout_navigation.addWidget(self.min_button, 0, 1)
self.layout_navigation.addWidget(self.max_button, 0, 2)
self.layout_navigation.addWidget(self.close_button, 0, 3)
self.layout_navigation.setContentsMargins(0, 0, 0, 0)
self.vbox_2 = QVBoxLayout(self)
self.vbox_2.addWidget(self.top_bar)
self.vbox_2.addWidget(self.content)
self.vbox_2.setContentsMargins(0, 0, 0, 0)
self.vbox_2.setSpacing(0)
def turn_window(self):
self.showMinimized()
def expand_window(self):
self.showMaximized()
+++ vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
if self.isMaximized():
self.max_button.setIcon(QIcon("maximize.svg")) # !
self.showNormal()
else:
self.max_button.setIcon(QIcon("minimize.svg")) # !
self.showMaximized()
+++ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
def close_window(self):
sys.exit(0)
self.close()
+++ vvv теперь вы можете перемещать окно
def mousePressEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
self.offset = event.pos()
else:
super().mousePressEvent(event)
def mouseMoveEvent(self, event):
if self.offset is not None and event.buttons() == QtCore.Qt.LeftButton:
self.move(self.pos() + event.pos() - self.offset)
else:
super().mouseMoveEvent(event)
def mouseReleaseEvent(self, event):
self.offset = None
super().mouseReleaseEvent(event)
+++ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if name == "main":
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())