Important: Please read the Qt Code of Conduct -

Position of QGraphicItem in a QGraphicScene

  • My aim is that the graphics items inside a qgraphicsview should not move when I resize the GraphicsView window.

    1. Currently, they seem to be in a default layout inside the graphics scene. When I resize the graphics view, the items move along with it.
    2. When I try to print a QGraphicitem->scenePos, the value does not change when I resize the QGraphicsView which contains the QGraphicsScene. ```
      QGraphicsView *view = new QGraphicsView(this);
      QGraphicsScene *scene = new QGraphicsScene();
      QGraphicsItem *imageItem=scene()->addWidget(pixmap);

  • Moderators

    you would need to scale the view whenever a resize happens.
    This can be done with fitInView() or scale() "manually"

  • I had the same problem with items moving rightward as I stretched the window/viewport beyond the scene rect. This fixed it:

    view->setAlignment( Qt::AlignLeft | Qt::AlignTop );