Class: QgsLayoutViewTool

Abstract base class for all layout view tools. Layout view tools are user interactive tools for manipulating and adding items to QgsLayoutView widgets.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsLayoutViewTool

Base classes

QObject

Subclasses

QgsLayoutViewToolAddItem

Layout view tool for adding items to a layout.

QgsLayoutViewToolAddNodeItem

Layout view tool for adding node based items to a layout.

QgsLayoutViewToolEditNodes

Layout view tool for edit node based items in the layout.

QgsLayoutViewToolMoveItemContent

Layout view tool for moving and zooming item content.

QgsLayoutViewToolPan

Layout view tool for panning the layout.

QgsLayoutViewToolSelect

Layout view tool for selecting items in the layout.

QgsLayoutViewToolTemporaryKeyPan

Layout view tool for temporarily panning a layout while a key is depressed.

QgsLayoutViewToolZoom

Layout view tool for zooming into and out of the layout.

QgsLayoutViewToolTemporaryMousePan

Layout view tool for temporarily panning a layout while a mouse button is depressed.

Methods

action

Returns the action associated with the tool or None if no action is associated.

activate

Called when tool is set as the currently active layout tool.

deactivate

Called when tool is deactivated.

flags

Returns the current combination of flags set for the tool.

ignoredSnapItems

Returns a list of items which should be ignored while snapping events for this tool.

isClickAndDrag

Returns True if a mouse press/release operation which started at startViewPoint and ended at endViewPoint should be considered a "click and drag".

keyPressEvent

Key press event for overriding.

keyReleaseEvent

Key release event for overriding.

layout

Returns the layout associated with the tool.

layoutDoubleClickEvent

Mouse double-click event for overriding.

layoutMoveEvent

Mouse move event for overriding.

layoutPressEvent

Mouse press event for overriding.

layoutReleaseEvent

Mouse release event for overriding.

setAction

Associates an action with this tool.

setCursor

Sets a user defined cursor for use when the tool is active.

setFlags

Sets the combination of flags that will be used for the tool.

toolName

Returns a user-visible, translated name for the tool.

view

Returns the view associated with the tool.

wheelEvent

Mouse wheel event for overriding.

Signals

activated

Emitted when the tool is activated.

deactivated

Emitted when the tool is deactivated.

itemFocused

Emitted when an item is "focused" by the tool, i.e. it should become the active item and should have its properties displayed in any designer windows.

Attributes

FlagSnaps

class qgis.gui.QgsLayoutViewTool[source]

Bases: QObject

__init__(view: QgsLayoutView | None, name: str | None)

Constructor for QgsLayoutViewTool, taking a layout view and tool name as parameters.

Parameters:
class Flag

Bases: int

FlagSnaps = 2
class Flags
class Flags(f: QgsLayoutViewTool.Flags | QgsLayoutViewTool.Flag)
class Flags(a0: QgsLayoutViewTool.Flags)

Bases: object

action(self) QAction | None[source]

Returns the action associated with the tool or None if no action is associated.

See also

setAction()

Return type:

Optional[QAction]

activate(self)[source]

Called when tool is set as the currently active layout tool. Overridden implementations must take care to call the base class implementation.

signal activated[source]

Emitted when the tool is activated.

deactivate(self)[source]

Called when tool is deactivated. Overridden implementations must take care to call the base class implementation.

signal deactivated[source]

Emitted when the tool is deactivated.

flags(self) QgsLayoutViewTool.Flags[source]

Returns the current combination of flags set for the tool.

See also

setFlags()

Return type:

QgsLayoutViewTool.Flags

ignoredSnapItems(self) List[QgsLayoutItem]

Returns a list of items which should be ignored while snapping events for this tool.

Return type:

List[QgsLayoutItem]

isClickAndDrag(self, startViewPoint: QPoint, endViewPoint: QPoint) bool[source]

Returns True if a mouse press/release operation which started at startViewPoint and ended at endViewPoint should be considered a “click and drag”. If False is returned, the operation should be instead treated as just a click on startViewPoint.

Parameters:
  • startViewPoint (QPoint)

  • endViewPoint (QPoint)

Return type:

bool

signal itemFocused(item: QgsLayoutItem)[source]

Emitted when an item is “focused” by the tool, i.e. it should become the active item and should have its properties displayed in any designer windows.

Parameters:

item (QgsLayoutItem)

keyPressEvent(self, event: QKeyEvent | None)[source]

Key press event for overriding. Default implementation does nothing.

Parameters:

event (Optional[QKeyEvent])

keyReleaseEvent(self, event: QKeyEvent | None)[source]

Key release event for overriding. Default implementation does nothing.

Parameters:

event (Optional[QKeyEvent])

layout(self) QgsLayout | None[source]

Returns the layout associated with the tool.

See also

view()

Return type:

Optional[QgsLayout]

layoutDoubleClickEvent(self, event: QgsLayoutViewMouseEvent | None)[source]

Mouse double-click event for overriding. Default implementation does nothing.

Parameters:

event (Optional[QgsLayoutViewMouseEvent])

layoutMoveEvent(self, event: QgsLayoutViewMouseEvent | None)[source]

Mouse move event for overriding. Default implementation does nothing.

Parameters:

event (Optional[QgsLayoutViewMouseEvent])

layoutPressEvent(self, event: QgsLayoutViewMouseEvent | None)[source]

Mouse press event for overriding. Default implementation does nothing. Note that subclasses must ensure that they correctly handle cases when a layoutPressEvent is called without a corresponding layoutReleaseEvent (e.g. due to tool being changed mid way through a press-release operation).

Parameters:

event (Optional[QgsLayoutViewMouseEvent])

layoutReleaseEvent(self, event: QgsLayoutViewMouseEvent | None)[source]

Mouse release event for overriding. Default implementation does nothing. Note that subclasses must ensure that they correctly handle cases when a layoutPressEvent is called without a corresponding layoutReleaseEvent (e.g. due to tool being changed mid way through a press-release operation).

Parameters:

event (Optional[QgsLayoutViewMouseEvent])

setAction(self, action: QAction | None)[source]

Associates an action with this tool. When the setLayoutTool method of QgsLayoutView is 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

action()

Parameters:

action (Optional[QAction])

setCursor(self, cursor: QCursor | Qt.CursorShape)[source]

Sets a user defined cursor for use when the tool is active.

Parameters:

cursor (Union[QCursor, Qt.CursorShape])

setFlags(self, flags: QgsLayoutViewTool.Flags | QgsLayoutViewTool.Flag)[source]

Sets the combination of flags that will be used for the tool.

See also

flags()

Parameters:

flags (Union[QgsLayoutViewTool.Flags, QgsLayoutViewTool.Flag])

toolName(self) str[source]

Returns a user-visible, translated name for the tool.

Return type:

str

view(self) QgsLayoutView | None[source]

Returns the view associated with the tool.

See also

layout()

Return type:

Optional[QgsLayoutView]

wheelEvent(self, event: QWheelEvent | None)[source]

Mouse wheel event for overriding. Default implementation does nothing.

Parameters:

event (Optional[QWheelEvent])