QGraphicsPixmapItem is shifting while zooming and panning
-
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.
-
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.
-
@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".@Pl45m4 Thank you for your answer. When I put the marker for example here:
If I zoom, then the marker shifts to another place on the map (here somewhere in the top left):
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?