Subgroup: Map

Class: QgsMapMouseEvent

class qgis.gui.QgsMapMouseEvent(mapCanvas: QgsMapCanvas, event: QMouseEvent)

Bases: PyQt5.QtGui.QMouseEvent

Creates a new QgsMapMouseEvent. Should only be required to be called from the QgsMapCanvas.

Parameters:
  • mapCanvas – The map canvas on which the event occurred
  • event – The original mouse event

QgsMapMouseEvent(mapCanvas: QgsMapCanvas, type: QEvent.Type, pos: QPoint, button: Qt.MouseButton = Qt.NoButton, buttons: Union[Qt.MouseButtons, Qt.MouseButton] = Qt.NoButton, modifiers: Union[Qt.KeyboardModifiers, Qt.KeyboardModifier] = Qt.NoModifier) Creates a new QgsMapMouseEvent. Should only be required to be called from the QgsMapCanvas.

Parameters:
  • mapCanvas – The map canvas on which the event occurred
  • type – The type of the event
  • pos – The pixel position of the mouse
  • button – The pressed button
  • buttons – Further buttons that are pressed
  • modifiers – Keyboard modifiers

QgsMapMouseEvent(QgsMapMouseEvent)

A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas. It is sent whenever the user moves, clicks, releases or double clicks the mouse. In addition to the coordinates in pixel space it also knows the coordinates in the mapcanvas’ CRS as well as it knows the concept of snapping.

Methods

isSnapped Returns true if there is a snapped point cached.
mapPoint mapPoint returns the point in coordinates
mapPointMatch Returns the matching data from the most recently snapped point.
originalMapPoint Returns the original, unmodified map point of the mouse cursor.
originalPixelPoint The unsnapped, real mouse cursor position in pixel coordinates.
pixelPoint The snapped mouse cursor in pixel coordinates.
setMapPoint Set the (snapped) point this event points to in map coordinates.
snapPoint snapPoint will snap the points using the map canvas snapping utils configuration

Signals

Attributes

isSnapped(self) → bool

Returns true if there is a snapped point cached. Will only be useful after snapPoint has previously been called.

Returns:True if there is a snapped point cached.
mapPoint(self) → QgsPointXY

mapPoint returns the point in coordinates

Returns:the point in map coordinates, after snapping if requested in the event.
mapPointMatch(self) → QgsPointLocator.Match

Returns the matching data from the most recently snapped point.

Returns:the snapping data structure

Note

This method returns the most recent snap match. It must follow a call to snapPoint() in order to have a recent snap result available.

New in version 2.14.

originalMapPoint(self) → QgsPointXY

Returns the original, unmodified map point of the mouse cursor.

Returns:The cursor position in map coordinates.
originalPixelPoint(self) → QPoint

The unsnapped, real mouse cursor position in pixel coordinates. Alias to pos()

Returns:Mouse position in pixel coordinates
pixelPoint(self) → QPoint

The snapped mouse cursor in pixel coordinates.

Returns:The snapped mouse cursor position in pixel coordinates.
setMapPoint(self, point: QgsPointXY)

Set the (snapped) point this event points to in map coordinates. The point in pixel coordinates will be calculated accordingly.

Parameters:point – The point in map coordinates
snapPoint(self) → QgsPointXY

snapPoint will snap the points using the map canvas snapping utils configuration

Note

if snapping did not succeeded, the map point will be reset to its original position