Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Scale items position relative to the scene/view resizing

Scale items position relative to the scene/view resizing

Scheduled Pinned Locked Moved Solved General and Desktop
qt5qgraphicssceneqgraphicsviewqgraphicsitem
3 Posts 3 Posters 2.2k Views 3 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.
  • A Offline
    A Offline
    alizadeh91
    wrote on last edited by
    #1

    I'm developing a software using Qt. I have a QGraphicsView that can be resized.

    I want to let users load an image (some maps) as the background of the view and be able to place some markers on the image (QGraphicsPixmapItem) and move them around. The positions of the markers on the image are important to be kept since they are markers on the map.

    If users try to resize the view by resizing the window, the image will be also resized. So the markers will not be at the previous positions of the map.

    It seems that the markers positions should also be scaled to the view.

    So my question is how to fix items position on the map even while resizing?

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      well, that's going to involve some math. Yes, you need to scale the x,y locations percentage based on the new image percent increase or decrease..

      For the map visual to remain valid you must keep the same aspect ratio, so essentially it's just a scale factor. Multiply the scale factor by the x and y components of each marker location to get the new location.

      If you meet the AI on the road, kill it.

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        Call fitInView on the GraphicsView with the Image whenever the size of the GraphicsView changes. The rest should work automatically.

        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 Extensions
        • Unsolved