Hi,
when i click into the graphicsView with the following example a QGraphicsEllipseItem will be added.
My problem is that the already existing QGraphicsEllipseItems seem to "mov"e each time when a new item is added.
I want the visible are of the scene to be fixed.

When i set the scene rect to a fixed rect, the items stay in position, but then the scene rect is not correct.
I want the sceneRect to include all items and thad the visible area of the scene stays fixed when i add new items.

Can anyone help?

Qt Code:
  1. #include <QGraphicsScene>
  2. #include <QGraphicsView>
  3. #include <QApplication>
  4. #include <QGraphicsEllipseItem>
  5. #include <QMouseEvent>
  6. #include <QPointF>
  7.  
  8. class MyView : public QGraphicsView {
  9. public:
  10. void mousePressEvent(QMouseEvent *event) {
  11. QPointF pos = mapToScene(event->pos());
  12. scene()->addItem(new QGraphicsEllipseItem(pos.x()-5,pos.y()-5,10,10));
  13. }
  14. };
  15.  
  16. int main(int argc, char **argv) {
  17.  
  18. QApplication app(argc, argv);
  19.  
  20. MyView v;
  21. v.setScene(&scene);
  22. v.show();
  23.  
  24. return app.exec();
  25.  
  26. }
To copy to clipboard, switch view to plain text mode