3

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...

iface.mapCanvas().???.connect(self.info)
1
  • By moved you mean moving the viewport, the position in the legend or the actual file/database where the layer/map is? Apr 21, 2013 at 17:54

1 Answer 1

7

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" )

iface.mapCanvas().extentsChanged.connect(info)

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

iface.mapCanvas().extent()
4
  • @underdark This should also work for QGIS 2.x, doesn't it? Sep 29, 2013 at 9:14
  • The signal/slot mechanism has changed, see gis.stackexchange.com/questions/72696/…
    – underdark
    Sep 30, 2013 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). Sep 30, 2013 at 13:30
  • sorry, my fault
    – underdark
    Sep 30, 2013 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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