I want to get a message when every time I move the map.

I had:

def info(self):
    QMessageBox.information( self, self.tr( "Info" ), self.tr("info") )

I suppose that used to be something like that...

  • By moved you mean moving the viewport, the position in the legend or the actual file/database where the layer/map is? – lynxlynxlynx Apr 21 '13 at 17:54

What you are looking for is the extentsChanged() signal. This is emitted every time, the map canvas is moved or zoomed.

The following code works from the python console:

from PyQt4.QtGui import QMessageBox

def info():
    QMessageBox.information( iface.mapCanvas(), "Extents changed", "Pan or zoom occurred" )


Adjusting it to be used from a a python object (like in a plugin) should be easy, the necessary self-parameters are in the question code already.

There is no information about the new extents emitted with the signal, but this can be easily queried with

  • @underdark This should also work for QGIS 2.x, doesn't it? – Matthias Kuhn Sep 29 '13 at 9:14
  • The signal/slot mechanism has changed, see gis.stackexchange.com/questions/72696/… – underdark Sep 30 '13 at 13:13
  • They are different use-cases available in both versions. The signal mentioned in this answer only gets emitted when the extent changes (pan / zoom) the other one gets emitted whenever the map canvas is repainted (e.g. symbology change). – Matthias Kuhn Sep 30 '13 at 13:30
  • sorry, my fault – underdark Sep 30 '13 at 18:44

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.