问题遇到的现象和发生背景
我写出这样的代码,用Window类去调用MyWidget,MyWidget不显示,求解
运行结果及报错内容
MyWidget无法显示
我写出这样的代码,用Window类去调用MyWidget,MyWidget不显示,求解
MyWidget无法显示
import sys
from PyQt5.QtCore import Qt, QRect
from PyQt5.QtGui import QPainter
from PyQt5.QtWidgets import QApplication, QWidget
class MyWidget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.resize(300, 300)
self.move(100, 100)
self.setAttribute(Qt.WA_StyledBackground, True)
self.setStyleSheet("background-color:yellow;")
class Window(QWidget):
def __init__(self):
super().__init__()
self.resize(500, 500)
self.move(200, 200)
self.setStyleSheet("background-color:blue;")
q_widget = MyWidget(self)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec())