Class: QgsPlotTool¶
Abstract base class for all interactive plot tools.
Plot tools are user tools for manipulating and interacting with a
QgsPlotCanvas.
Added in version 3.26.
Class Hierarchy¶
Base classes¶
Subclasses¶
Plot tool for panning/zoom/navigating plots. |
|
Plot tool for temporarily panning a plot while a key is depressed. |
|
Plot tool for zooming into and out of the plot. |
|
Plot tool for temporarily panning a plot while a mouse button is depressed. |
Methods
Returns the action associated with the tool or |
|
Returns the tool's plot canvas. |
|
Returns |
|
Returns |
|
Associates an action with this tool. |
|
Sets a user defined cursor for use when the tool is active. |
|
Converts a point in map coordinates to the associated canvas point. |
|
Converts a point on the canvas to the associated map coordinate. |
|
Returns a user-visible, translated name for the tool. |
Virtual Methods
In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsPlotTool. See the FAQ for more details.
Called when the tool is set as the currently active plot tool. |
|
Tooltip event for overriding. |
|
Called when the tool is being deactivated. |
|
Returns the flags for the plot tool. |
|
Gesture event for overriding. |
|
Key press event for overriding. |
|
Key release event for overriding. |
|
Mouse double-click event for overriding. |
|
Mouse move event for overriding. |
|
Mouse press event for overriding. |
|
Mouse release event for overriding. |
|
Allows the tool to populate and customize the given menu, prior to showing it in response to a right-mouse button click. |
|
Mouse wheel event for overriding. |
Static Methods
Constrains a point to force it to fall within the specified rectangle. |
Signals
Emitted when the tool is activated. |
|
Emitted when the tool is deactivated |
- class qgis.gui.QgsPlotTool[source]¶
Bases:
QObject- __init__(canvas: QgsPlotCanvas | None, name: str | None)
Constructor takes a plot canvas as a parameter.
- Parameters:
canvas (Optional[QgsPlotCanvas])
name (Optional[str])
- action(self) QAction | None[source]¶
Returns the action associated with the tool or
Noneif no action is associated.See also
- Return type:
Optional[QAction]
- canvas(self) QgsPlotCanvas | None[source]¶
Returns the tool’s plot canvas.
- Return type:
Optional[QgsPlotCanvas]
- virtual canvasToolTipEvent(self, event: QHelpEvent | None) bool[source]¶
Tooltip
eventfor overriding.Returns
Trueif the event was handled by the tool and should not be propagated further.- Parameters:
event (Optional[QHelpEvent])
- Return type:
bool
- static constrainPointToRect(point: QPointF | QPoint, rect: QRectF) QPointF[source]¶
Constrains a point to force it to fall within the specified rectangle.
- Parameters:
point (Union[QPointF, QPoint])
rect (QRectF)
- Return type:
QPointF
- virtual flags(self) Qgis.PlotToolFlags[source]¶
Returns the flags for the plot tool.
- Return type:
- virtual gestureEvent(self, event: QGestureEvent | None) bool[source]¶
Gesture
eventfor overriding.Returns
Trueif the event was handled by the tool and should not be propagated further.- Parameters:
event (Optional[QGestureEvent])
- Return type:
bool
- isActive(self) bool[source]¶
Returns
Trueif this tool is the current tool active on the plot canvas.- Return type:
bool
- isClickAndDrag(self, startViewPoint: QPoint, endViewPoint: QPoint) bool[source]¶
Returns
Trueif a mouse press/release operation which started atstartViewPointand ended atendViewPointshould be considered a “click and drag”. IfFalseis returned, the operation should be instead treated as just a click onstartViewPoint.- Parameters:
startViewPoint (QPoint)
endViewPoint (QPoint)
- Return type:
bool
- virtual keyPressEvent(self, event: QKeyEvent | None)[source]¶
Key press
eventfor overriding.The default implementation does nothing. When subclasses implement this method and have acted on the event, they must explicitly call event->:py:func:~QgsPlotTool.accept to prevent the event from being passed on to other widgets.
- Parameters:
event (Optional[QKeyEvent])
- virtual keyReleaseEvent(self, event: QKeyEvent | None)[source]¶
Key release
eventfor overriding.The default implementation does nothing. When subclasses implement this method and have acted on the event, they must explicitly call event->:py:func:~QgsPlotTool.accept to prevent the event from being passed on to other widgets.
- Parameters:
event (Optional[QKeyEvent])
- virtual plotDoubleClickEvent(self, event: QgsPlotMouseEvent | None)[source]¶
Mouse double-click
eventfor overriding.The default implementation does nothing. When subclasses implement this method and have acted on the event, they must explicitly call event->:py:func:~QgsPlotTool.accept to prevent the event from being passed on to other widgets.
- Parameters:
event (Optional[QgsPlotMouseEvent])
- virtual plotMoveEvent(self, event: QgsPlotMouseEvent | None)[source]¶
Mouse move
eventfor overriding.The default implementation does nothing. When subclasses implement this method and have acted on the event, they must explicitly call event->:py:func:~QgsPlotTool.accept to prevent the event from being passed on to other widgets.
- Parameters:
event (Optional[QgsPlotMouseEvent])
- virtual plotPressEvent(self, event: QgsPlotMouseEvent | None)[source]¶
Mouse press
eventfor overriding.The default implementation does nothing. When subclasses implement this method and have acted on the event, they must explicitly call event->:py:func:~QgsPlotTool.accept to prevent the event from being passed on to other widgets.
- Parameters:
event (Optional[QgsPlotMouseEvent])
- virtual plotReleaseEvent(self, event: QgsPlotMouseEvent | None)[source]¶
Mouse release
eventfor overriding.The default implementation does nothing. When subclasses implement this method and have acted on the event, they must explicitly call event->:py:func:~QgsPlotTool.accept to prevent the event from being passed on to other widgets.
- Parameters:
event (Optional[QgsPlotMouseEvent])
- virtual populateContextMenuWithEvent(self, menu: QMenu | None, event: QgsPlotMouseEvent | None) bool[source]¶
Allows the tool to populate and customize the given
menu, prior to showing it in response to a right-mouse button click.menuwill be initially populated with a set of default, generic actions. Any new actions added to the menu should be correctly parented tomenu.A pointer to the plot mouse
eventcan be provided to allow particular behavior depending on the plot tool.This method can return
Trueto inform the caller that the menu was effectively populated.The default implementation does nothing and returns
False.Note
The context menu is only shown when the ShowContextMenu flag is present in
flags().- Parameters:
menu (Optional[QMenu])
event (Optional[QgsPlotMouseEvent])
- Return type:
bool
- setAction(self, action: QAction | None)[source]¶
Associates an
actionwith this tool. When the setTool method ofQgsPlotCanvasis called the action’s state will be set to on. Usually this will cause a toolbutton to appear pressed in and the previously used toolbutton to pop out.See also
- Parameters:
action (Optional[QAction])
- setCursor(self, cursor: QCursor | Qt.CursorShape)[source]¶
Sets a user defined
cursorfor use when the tool is active.- Parameters:
cursor (Union[QCursor, Qt.CursorShape])
- toCanvasCoordinates(self, point: QgsPoint) QgsPointXY[source]¶
Converts a
pointin map coordinates to the associated canvas point.May return an empty point if the map point cannot be converted to a canvas point.
- Parameters:
point (QgsPoint)
- Return type:
- toMapCoordinates(self, point: QgsPointXY) QgsPoint[source]¶
Converts a
pointon the canvas to the associated map coordinate.May return an empty point if the canvas point cannot be converted to a map point.
- Parameters:
point (QgsPointXY)
- Return type:
- virtual wheelEvent(self, event: QWheelEvent | None)[source]¶
Mouse wheel
eventfor overriding.The default implementation does nothing. When subclasses implement this method and have acted on the event, they must explicitly call event->:py:func:~QgsPlotTool.accept to prevent the event from being passed on to other widgets.
- Parameters:
event (Optional[QWheelEvent])