- Announcing the release of QGIS 1.4.0 'Enceladus'
- Carson Farmer's report back on the Vienna Hackfest
- Vienna Hackfest 2009 Report Back
- Introducing the QGIS Hackfest (Vienna 2009) crew
- Announcing the release of QGIS 1.3.0 'Mimas'
- Announcing the releases of QGIS 1.0.2 (stable) and QGIS 1.1.0 'Pan' (unstable).
- Summer of Code project: Label placement
- QGIS and Google Summer of Code 2009
- QGIS Is And Will Remain Free Open Source Software
- QGIS Going Closed Source
Capturing map coordinates in a stand alone app...
Submitted by aaronr on Thu, 2008-01-24 18:51.

For those of you striving to build some stand alone Python apps based on the QGIS Python bindings here is a quick snip for ya:
class MapCoords(object):
def __init__(self, mainwindow):
self.mainwindow = mainwindow
# This one is to capture the mouse move for coordinate display
QObject.connect(mainwindow.canvas, SIGNAL("xyCoordinates(QgsPoint&)"),
self.updateCoordsDisplay)
self.latlon = QLabel("0.0 , 0.0")
self.latlon.setFixedWidth(200)
self.latlon.setAlignment(Qt.AlignHCenter)
self.latlon.setFrameStyle(QFrame.StyledPanel)
self.mainwindow.statusbar.addPermanentWidget(self.latlon)
# Signal handeler for updating coord display
def updateCoordsDisplay(self, p):
capture_string = QString(str(p.x()) + " , " +
str(p.y()))
self.latlon.setText(capture_string)
From your main app (QMainWindow object) just create one of these objects:
# New Map Coords display in status bar
self.mapcoords = MapCoords(self)
Thats all there is to it... hook up to the main canvas xyCoordinates signal and you just update a simple QLabel on the status bar of the main window.
Go forth and code...
Aaron
EMAIL: aaronr (at) z-pulley.com
WEB : http://www.reprojected.com
»
- aaronr's blog
- Login or register to post comments
- 10075 reads

API change
Qgis 1.3 (and possibly before) uses a slightly different signal definition:
SIGNAL("xyCoordinates(const QgsPoint &)")
- and if you don't put in the const, the signals just don't happen!