0

I'm using

QgisInterface->mapCanvas()->scene()->addItem(QGraphicsTextItem)

to add a QGraphicsTextItem to the map canvas. The problem is that when I use the pan tool to move the display the added QGraphicsTextItem is not moving !
How can I make it update its position whenever the pan tool is used on the map ?

1

You need to align the position of the item to the new canvas extent. Either connect to the QgsMapCanvas::extentsChanged() signal and update the QGraphicsTextItem from there. Or derive a class from QgsMapCanvasItem and implement a paint method that takes the current map canvas extent into account (QgsMapCanvasItem has some methods in that direction).

QgsTextAnnotationItem might also fit your needs or at least be an example how to implement your class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.