from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class AAA(QGraphicsView):
def __init__(self):
super().__init__()
self.resize(1280, 720)
self.setStyleSheet('background:white')
self.show()
Xscene = QGraphicsScene()
self.setScene(Xscene)
gray_square=qDrawPlainRect(200,100)
Xscene.addItem(gray_square)
A = QApplication(sys.argv)
aaa = AAA()
A.exec_()
答案 0 :(得分:0)
你其实非常接近。请尝试以下方法。
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class AAA(QGraphicsView):
def __init__(self):
super().__init__()
self.resize(1280, 720)
self.setStyleSheet('background:white')
self.show()
Xscene = QGraphicsScene()
self.setScene(Xscene)
# gray_square=qDrawPlainRect(200,100)
gray_square = QGraphicsRectItem(0, 0, 200, 100)
gray_square.setPen(Qt.gray)
gray_square.setBrush(QBrush((Qt.gray)))
Xscene.addItem(gray_square)
A = QApplication(sys.argv)
aaa = AAA()
A.exec_()