At the documentation for
QGraphicsScene, there is a simple example that does not work as written. I've written a fix that does work, and am curious if it could be improved.
From the docs (does not work as is):
scene = QGraphicsScene() scene.addText("Hello, world!") view = QGraphicsView(&scene) view.show()
Fixed version that does work:
from PySide import QtGui import sys class MyFirstScene(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.scene=QtGui.QGraphicsScene(self) self.scene.addText("Hello, world!") self.view = QtGui.QGraphicsView(self.scene, self) self.show() if __name__=="__main__": app=QtGui.QApplication(sys.argv) firstScene = MyFirstScene() sys.exit(app.exec_())
My question is whether I can simplify this more, making it more like the example in the documentation. I tried doing it without making the scene an attribute of
QWidget, which breaks it. But perhaps I'm missing a simpler working implementation of the documentation's skeleton?