def __init__(self, parent=None):
initialSceneRect
= QRectF(-10,
-10,
20,
20) # Widgets
# Layout
layout.addWidget(self.view)
# Add items to scene
self.scene.addItem(it)
#def sizeHint(self):
# return QSize(600,600)
def keyPressEvent(self, evt):
""" quick and dirty way to add an object on the fly"""
self.scene.addItem(it)
self.
view.
updateSceneRect(QRectF(-1100,
-1100,
2200,
2200))
def main():
w = Window()
w.show()
app.exec_()
main()
class Window(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
initialSceneRect = QRectF(-10, -10, 20, 20)
self.scene = QGraphicsScene(initialSceneRect)
# Widgets
self.view = QGraphicsView(self.scene, self)
# Layout
layout = QHBoxLayout(self)
layout.addWidget(self.view)
# Add items to scene
it = QGraphicsRectItem(QRectF(-100, -100, 200, 200))
it.setPos(QPointF(0, 0))
self.scene.addItem(it)
#def sizeHint(self):
# return QSize(600,600)
def keyPressEvent(self, evt):
""" quick and dirty way to add an object on the fly"""
it = QGraphicsRectItem(QRectF(-1000, -1000, 2000, 2000))
it.setPos(QPointF(0, 0))
self.scene.addItem(it)
self.view.updateSceneRect(QRectF(-1100, -1100, 2200, 2200))
def main():
app = QApplication([])
w = Window()
w.show()
app.exec_()
main()
To copy to clipboard, switch view to plain text mode
Bookmarks