Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Position of QGraphicItem in a QGraphicScene
Qt 6.12 LTS is out! See what's new in the release blog

Position of QGraphicItem in a QGraphicScene

Scheduled Pinned Locked Moved Unsolved General and Desktop
qgraphicsitemqgraphicssceneqgraphicsview
3 Posts 3 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sunil.nair
    wrote on last edited by
    #1

    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);
      view->setScene(scene);
    raven-worxR 1 Reply Last reply
    0
    • S sunil.nair

      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);
        view->setScene(scene);
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

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

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • R Offline
        R Offline
        remik
        wrote on last edited by
        #3

        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 );

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved