QGIS 3 Get coordinates from mouse click
In a plugin (displayed "Always On Top"), with PyQGIS 3, to avoid it jumps right to the end without calling the display_point function you need following changes in your code:
.
.
.
from PyQt5.QtCore import Qt
from qgis.gui import QgsMapToolEmitPoint
.
.
.
def __init__(self, iface):
"""Constructor.
.
.
.
# Create the dialog (after translation) and keep reference
self.dlg = WhereAmIDialog()
self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint)
.
.
.
def initGui(self):
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
.
.
.
result = self.pointTool.canvasClicked.connect(self.display_point)
.
.
.
def display_point(self, point, button):
# report map coordinates from a canvas click
coords = "{}, {}".format(point.x(), point.y())
self.dlg.lineEdit.setText(str(coords))
self.dlg.show()
.
.
.
def run(self):
"""Run method that performs all the real work"""
# make our clickTool the tool that we'll use for now
self.canvas.setMapTool(self.pointTool)
.
.
.
It works; as it can be observed at following image: