Class: 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.
Class Hierarchy¶
Base classes¶
Methods
Returns |
|
mapPoint returns the point in coordinates |
|
Returns the matching data from the most recently snapped point. |
|
Returns the original, unmodified map point of the mouse cursor. |
|
The unsnapped, real mouse cursor position in pixel coordinates. |
|
The snapped mouse cursor in pixel coordinates. |
|
Set the (snapped) point this event points to in map coordinates. |
|
snapPoint will snap the points using the map canvas snapping utils configuration |
|
Snaps the mapPoint to a grid with the given precision. |
- class qgis.gui.QgsMapMouseEvent[source]¶
Bases:
QMouseEvent
- __init__(mapCanvas: QgsMapCanvas | None, event: QMouseEvent | None)
Creates a new QgsMapMouseEvent. Should only be required to be called from the QgsMapCanvas.
- Parameters:
mapCanvas (Optional[QgsMapCanvas]) – The map canvas on which the event occurred
event (Optional[QMouseEvent]) – The original mouse event
- __init__(mapCanvas: QgsMapCanvas | None, type: QEvent.Type, pos: QPoint, button: Qt.MouseButton = Qt.NoButton, buttons: Qt.MouseButtons | Qt.MouseButton = Qt.NoButton, modifiers: Qt.KeyboardModifiers | Qt.KeyboardModifier = Qt.NoModifier)
Creates a new QgsMapMouseEvent. Should only be required to be called from the QgsMapCanvas.
- Parameters:
mapCanvas (Optional[QgsMapCanvas]) – The map canvas on which the event occurred
type (QEvent.Type) – The type of the event
pos (QPoint) – The pixel position of the mouse
button (Qt.MouseButton = Qt.NoButton) – The pressed button
buttons (Union[Qt.MouseButtons, Qt.MouseButton] = Qt.NoButton) – Further buttons that are pressed
modifiers (Union[Qt.KeyboardModifiers, Qt.KeyboardModifier] = Qt.NoModifier) – Keyboard modifiers
- __init__(a0: QgsMapMouseEvent)
- Parameters:
a0 (QgsMapMouseEvent)
- isSnapped(self) bool [source]¶
Returns
True
if there is a snapped point cached. Will only be useful after snapPoint has previously been called.- Return type:
bool
- Returns:
True
if there is a snapped point cached.
- mapPoint(self) QgsPointXY [source]¶
mapPoint returns the point in coordinates
- Return type:
- Returns:
the point in map coordinates, after snapping if requested in the event.
- mapPointMatch(self) QgsPointLocator.Match [source]¶
Returns the matching data from the most recently snapped point.
- Return type:
- 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.
- originalMapPoint(self) QgsPointXY [source]¶
Returns the original, unmodified map point of the mouse cursor.
- Return type:
- Returns:
The cursor position in map coordinates.
- originalPixelPoint(self) QPoint [source]¶
The unsnapped, real mouse cursor position in pixel coordinates. Alias to
pos()
- Return type:
QPoint
- Returns:
Mouse position in pixel coordinates
- pixelPoint(self) QPoint [source]¶
The snapped mouse cursor in pixel coordinates.
- Return type:
QPoint
- Returns:
The snapped mouse cursor position in pixel coordinates.
- setMapPoint(self, point: QgsPointXY)[source]¶
Set the (snapped) point this event points to in map coordinates. The point in pixel coordinates will be calculated accordingly.
- Parameters:
point (QgsPointXY) – The point in map coordinates
- snapPoint(self) QgsPointXY [source]¶
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
- Return type:
- snapToGrid(self, precision: float, crs: QgsCoordinateReferenceSystem)[source]¶
Snaps the mapPoint to a grid with the given
precision
. The snapping will be done in the specifiedcrs
. If this crs is different from the mapCanvas crs, it will be reprojected on the fly.Added in version 3.4.
- Parameters:
precision (float)