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. QGraphicsPixmapItem is shifting while zooming and panning
Forum Updated to NodeBB v4.3 + New Features

QGraphicsPixmapItem is shifting while zooming and panning

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 318 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.
  • K Offline
    K Offline
    korai
    wrote on last edited by korai
    #1

    I am using Qt and QGIS API to create a GUI. I added a marker/icon to the QGraphicsScene as Pixmap item.

    mpMapCanvas = new QgsMapCanvas(); 
    scene = mpMapCanvas->scene();
    QPixmap pixmap = QPixmap(":/mapMarker.png");
    icon = new QGraphicsPixmapItem(pixmap);
    scene->addItem(icon);
    
    icon->setPos(pointf.x(), pointf.y());   // pointf is a point (coordinates) in type QPointF
    icon->show();
    

    When zooming and panning, the item is shifting. To solve this problem, I tried

    icon->setFlag(QGraphicsPixmapItem::ItemIgnoresTransformations,true);
    

    How can I prevent the shifting of the icon while zooming, panning etc. using C++ or Python? I want to fix its position.

    Pl45m4P 1 Reply Last reply
    0
    • K korai

      I am using Qt and QGIS API to create a GUI. I added a marker/icon to the QGraphicsScene as Pixmap item.

      mpMapCanvas = new QgsMapCanvas(); 
      scene = mpMapCanvas->scene();
      QPixmap pixmap = QPixmap(":/mapMarker.png");
      icon = new QGraphicsPixmapItem(pixmap);
      scene->addItem(icon);
      
      icon->setPos(pointf.x(), pointf.y());   // pointf is a point (coordinates) in type QPointF
      icon->show();
      

      When zooming and panning, the item is shifting. To solve this problem, I tried

      icon->setFlag(QGraphicsPixmapItem::ItemIgnoresTransformations,true);
      

      How can I prevent the shifting of the icon while zooming, panning etc. using C++ or Python? I want to fix its position.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @korai said in QGraphicsPixmapItem is shifting while zooming and panning:

      How can I prevent the shifting

      What do you mean by "shifting"?
      If you zoom the scene, you need to re-calculate the position of the item, when you want to keep it "static".


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      K 1 Reply Last reply
      2
      • Pl45m4P Pl45m4

        @korai said in QGraphicsPixmapItem is shifting while zooming and panning:

        How can I prevent the shifting

        What do you mean by "shifting"?
        If you zoom the scene, you need to re-calculate the position of the item, when you want to keep it "static".

        K Offline
        K Offline
        korai
        wrote on last edited by korai
        #3

        @Pl45m4 Thank you for your answer. When I put the marker for example here:
        2022-03-11_13-51.png

        If I zoom, then the marker shifts to another place on the map (here somewhere in the top left):
        2022-03-11_13-52.png

        Like you said, I need to re-calculate the position, although I set its position when I put it with the following code:
        icon->setPos(pointf.x(), pointf.y());

        What should I do to re-calculate its position according to zooming/panning?

        1 Reply Last reply
        0

        • Login

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