I would like to add a graphic/image on the top left corner of my view, would it be possible to make it static, meaning that wherever we zoom to or pan, the graphic will still stay put.
With PyQGIS, you can add an image to the canvas. You will find below only a small part of the code you could used as proof of the idea.
I didn't do the positioning part of the rectangle in the canvas but I've added how to manage event when your canvas changed.
To try out:
- open a project with a world map using projection EPSG 4326.
- change the code sample to reference the image path
/tmp/test.pngwith your own (the image tested was for me a 100x100 red png image)
- run the code below from
zoom and pan changing the y position to see the image color changing.
from PyQt4.QtGui import QImage, QColor, QPixmap from qgis.utils import iface img = QImage('/tmp/test.png') pixmap = QPixmap.fromImage(img) canvas = iface.mapCanvas() ref_pixmap = canvas.scene().addPixmap(pixmap) def on_extents_changed(): center = canvas.center() print center.x(), center.y() new_pix = ref_pixmap.pixmap() if (center.y() >= -90 and center.y() < -45): new_pix.fill(QColor(255, 0, 255)) elif center.y() >= -45 and center.y() < 0: new_pix.fill(QColor(0, 0, 255)) elif center.y() >= 0 and center.y() < 45: new_pix.fill(QColor(255, 255, 0)) elif center.y() >= 45 and center.y() < 90: new_pix.fill(QColor(0, 255, 0)) ref_pixmap.setPixmap(new_pix) iface.mapCanvas().extentsChanged.connect(on_extents_changed)