I am developing a PyQt application for a Windows environment (no cross platform required), in which I need to create custom title bar for a QMainWindow
instance. There are suggestion to use self.setWindowFlags(Qt.FramelessWindowHint)
, but it creates undesired effect of application goes to fullscreen when maximizing it. Actually, there is solution which I believe to be the perfect solution for this case, that is drawing the NCA (Non Client Area) as describe in this page.
At the moment, this is my code:
class MainWindow(QMainWindow, Ui_MainWindow):
def winEvent(self, msg):
if msg.message == win32con.WM_NCPAINT:
self.decorate_window(msg)
return True, 0
return super(MainWindow, self).winEvent(msg)
def decorate_window(self, msg):
painter = QPainter(self)
painter.fillRect(self.rect(), QColor(255,0,0))
But it gives this warning, QPainter::begin: Paint device returned engine == 0, type: 1
, and there is no drawing occur except of a white titlebar and border.
Any suggestion?