I have been working on PyQt QMainWindow
QMdiArea
Class. I have been able to change the background colour as it is needed for my application.
However, I am unable to add a logo in the centre of the window.
I have tried QBrush but that just insert logo in full QMdiArea
.
Furthermore, I have tried paintEvent
overridden method but that seems to not work.
Please find enclosed my code and snapshot of the code output below:
# Import necessary libraries
import sys
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtGui import QColor, QBrush, QPainter
from PyQt5.QtWidgets import QStyleFactory, QWidget, QMainWindow, QMdiArea
class MDI_Window(QMainWindow, QWidget):
def __init__(self):
super().__init__()
self.centralWidget = QWidget(self)
self.mdi = QMdiArea()
self.setCentralWidget(self.mdi)
self.window_initialize()
self.show()
def window_initialize(self):
title = 'MDI'
self.setWindowTitle(title)
self.setWindowIcon(QtGui.QIcon("Some_Icon.png"))
self.setMinimumSize(800, 600)
self.mdi.setBackground(QBrush(QColor(169, 169, 169)))
self.showMaximized()
def paintEvent(self, event):
self.mdi.paintEvent(event)
self.painter = QPainter(self)
# For testing logo
self.painter.drawPixmap(500, 500, 500, 500, QtGui.QPixmap("KDS_Main-Window.png"))
if __name__ == "__main__":
# Create App with the design
LMS_App = QtWidgets.QApplication(sys.argv)
LMS_App.setStyle(QStyleFactory.create('Fusion'))
a = MDI_Window()
# Exit application when system is terminated
sys.exit(LMS_App.exec_())