I am trying to get the QgsMapCanvas
coordinates when they change using PyQt5
and PyQGIS 3. What I have used for that:
self.canvas.scaleChanged.connect(lambda: self.showScale(self.canvas.scale()))
self.canvas.xyCoordinates.connect(lambda: self.showXY(self.canvas.xyCoordinates()))
and functions definitions are
def showXY(self, p):
# SLOT. Show coordinates
self.lblXY.setText(str(p.x()) + " | " + str(p.y()))
def showScale(self, scale):
# SLOT. Show scale
self.lblScale.setText("Scale 1:" + str(scale))
I am able to get the scale but when the xyCoordiantes
is connected to the slot, window goes unresponsive and force closes.
What am I doing wrong?