我一直在研究 PyQtQMainWindow
QMdiArea
类。我已经能够根据我的应用程序的需要更改背景颜色。但是,我无法在窗口中心添加徽标。
我已经尝试过 QBrush,但只是插入了完整的徽标QMdiArea
。此外,我尝试过paintEvent
覆盖方法,但这似乎不起作用。
请在下面找到我的代码和代码输出的快照:
# 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_())