How to display a QGraphicsScene?
I've got the following code and I'm not sure how to add the QGraphicsScene to my layout..
class MainForm(QDialog): def __init__(self, parent=None): super(MainForm, self).__init__(parent) self.scene = QGraphicsScene(self) self.scene.setSceneRect(0, 0, 500, 500) self.view = QGraphicsView() self.view.setRenderHint(QPainter.Antialiasing) self.view.setScene(self.scene) self.view.setFocusPolicy(Qt.NoFocus) zoomSlider = QSlider(Qt.Horizontal) zoomSlider.setRange(5, 200) zoomSlider.setValue(100) self.pauseButton = QPushButton("Pause") quitButton = QPushButton("Quit") layout = QVBoxLayout() layout.addWidget(zoomSlider) self.setLayout(layout) self.startTimer(10)
How can I get my QGraphicsScene running? I'm new to Qt. Am I even supposed to be adding a QGraphicsScene to a layout/
You'll have to do something like this:
... layout = QVBoxLayout() layout.addWidget(zoomSlider) layout.addWidget(view) self.setLayout(layout) ...
You have added a scene to view, and it's enough. But you should add the view to your MainForm and Layout. View is a kind of widget that can be displayed by your application, while scene is not a widget and cannot be added to layout, it's a component of view. In addition, you may need to add some graphics items(e.g. rectangle, image) to scene and see how it works.