#!/usr/bin/env python3 from PySide2 import QtCore, QtGui, QtWidgets class Window(QtWidgets.QWidget): def __init__(self): super().__init__() scene = QtWidgets.QGraphicsScene() rect = scene.addRect(QtCore.QRectF(100,100,100,100), pen=QtGui.QPen(QtGui.QColor('red')), brush=QtGui.QBrush(QtGui.QColor('yellow')), ) view = QtWidgets.QGraphicsView(scene) self.scene = scene self.view = view self.rect = rect view.show() app = QtWidgets.QApplication([]) win = Window() #win.show() app.exec()