Class: QgsLayoutView

class qgis.gui.QgsLayoutView

Bases: PyQt5.QtWidgets.QGraphicsView

A graphical widget to display and interact with QgsLayouts.

QgsLayoutView manages the layout interaction tools and mouse/key events.

QgsLayoutView(parent: Optional[QWidget] = None) Constructor for QgsLayoutView.

Methods

actionEvent

alignSelectedItems

Aligns all selected items using the specified alignment.

changeEvent

childEvent

closeEvent

connectNotify

contextMenuEvent

copyItems

Cuts or copies the a list of items, respecting the specified operation.

copySelectedItems

Cuts or copies the selected items, respecting the specified operation.

create

currentLayout

Returns the current layout associated with the view.

currentPage

Returns the page visible in the view.

customEvent

deleteItems

Delete the specified items.

deleteSelectedItems

Deletes all selected items.

deltaForKeyEvent

Returns the delta (in layout coordinates) by which to move items for the given key event.

deselectAll

Deselects all items in the view.

destroy

disconnectNotify

distributeSelectedItems

Distributes all selected items using the specified distribution.

dragEnterEvent

param e:

dragLeaveEvent

dragMoveEvent

drawBackground

drawForeground

drawFrame

dropEvent

emitZoomLevelChanged

enterEvent

event

eventFilter

focusInEvent

focusNextChild

focusNextPrevChild

focusOutEvent

focusPreviousChild

groupSelectedItems

Groups all selected items.

hasItemsInClipboard

Returns True if the current clipboard contains layout items.

hideEvent

initPainter

initStyleOption

inputMethodEvent

invertSelection

Inverts the current selection, selecting deselected items and deselecting and selected items.

isSignalConnected

keyPressEvent

param event:

keyReleaseEvent

param event:

leaveEvent

lockSelectedItems

Locks any selected items, preventing them from being interacted with by mouse interactions.

lowerSelectedItems

Lowers the selected items down the z-order.

menuProvider

Returns the provider for context menus.

metric

mouseDoubleClickEvent

param event:

mouseMoveEvent

param event:

mousePressEvent

param event:

mouseReleaseEvent

param event:

moveEvent

moveSelectedItemsToBottom

Lowers the selected items to the bottom of the z-order.

moveSelectedItemsToTop

Raises the selected items to the top of the z-order.

nativeEvent

paintEvent

param event:

pasteItems

Pastes items from clipboard, using the specified mode.

previewMode

Returns the preview mode which may be used to modify the view's appearance.

previewModeEnabled

Returns True if a preview effect is being used to alter the view's appearance.

pushStatusMessage

Pushes a new status bar message to the view.

raiseSelectedItems

Raises the selected items up the z-order.

receivers

resizeEvent

param event:

resizeSelectedItems

Resizes all selected items using the specified resize mode.

scaleSafe

Scales the view in a safe way, by limiting the acceptable range of the scale applied.

scrollContentsBy

param dx:

selectAll

Selects all items in the view.

selectNextItemAbove

Selects the next item above the existing selection, by item z order.

selectNextItemBelow

Selects the next item below the existing selection, by item z order.

sender

senderSignalIndex

setCurrentLayout

Sets the current layout to edit in the view.

setHorizontalRuler

Sets a horizontal ruler to synchronize with the view state.

setMenuProvider

Sets a provider for context menus.

setPreviewMode

Sets the preview mode which should be used to modify the view's appearance.

setPreviewModeEnabled

Sets whether a preview effect should be used to alter the view's appearance.

setSectionLabel

Sets a section label, to display above the first page shown in the view.

setTool

Sets the tool currently being used in the view.

setVerticalRuler

Sets a vertical ruler to synchronize with the view state.

setViewportMargins

setZoomLevel

Sets the zoom level for the view, where a zoom level of 1.0 corresponds to 100%.

setupViewport

sharedPainter

showEvent

tabletEvent

timerEvent

tool

Returns the currently active tool for the view.

ungroupSelectedItems

Ungroups all selected items.

unlockAllItems

Unlocks all locked items in the layout.

unsetTool

Unsets the current view tool, if it matches the specified tool.

updateMicroFocus

viewChanged

Updates associated rulers and other widgets after view extent or zoom has changed.

viewportEvent

viewportMargins

viewportSizeHint

visiblePageNumbers

Returns a list of page numbers for pages which are currently visible in the view.

visiblePages

Returns a list of page items which are currently visible in the view.

wheelEvent

param event:

zoomActual

Zooms to the actual size of the layout.

zoomFull

Zooms the view to the full extent of the layout.

zoomIn

Zooms in to the view by a preset amount.

zoomOut

Zooms out of the view by a preset amount.

zoomWidth

Zooms the view to the full width of the layout.

Signals

cursorPosChanged

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

itemFocused

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

layoutSet

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

pageChanged

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

statusMessage

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

toolSet

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

willBeDeleted

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

zoomLevelChanged

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

Attributes

ClipboardCopy

ClipboardCut

PasteModeCenter

PasteModeCursor

PasteModeInPlace

ClipboardCopy = 1
ClipboardCut = 0
class ClipboardOperation

Bases: int

class PasteMode

Bases: int

PasteModeCenter = 1
PasteModeCursor = 0
PasteModeInPlace = 2
actionEvent(self, a0: QActionEvent | None)
alignSelectedItems(self, alignment: QgsLayoutAligner.Alignment)

Aligns all selected items using the specified alignment.

Parameters:

alignment (QgsLayoutAligner.Alignment)

changeEvent(self, a0: QEvent | None)
childEvent(self, a0: QChildEvent | None)
closeEvent(self, a0: QCloseEvent | None)
connectNotify(self, signal: QMetaMethod)
contextMenuEvent(self, event: QContextMenuEvent | None)
copyItems(self, items: Iterable[QgsLayoutItem], operation: QgsLayoutView.ClipboardOperation)

Cuts or copies the a list of items, respecting the specified operation.

See also

pasteItems()

Parameters:
copySelectedItems(self, operation: QgsLayoutView.ClipboardOperation)

Cuts or copies the selected items, respecting the specified operation.

See also

copyItems()

See also

pasteItems()

Parameters:

operation (QgsLayoutView.ClipboardOperation)

create(self, window: PyQt5.sip.voidptr = None, initializeWindow: bool = True, destroyOldWindow: bool = True)
currentLayout(self) QgsLayout | None

Returns the current layout associated with the view.

See also

layoutSet()

Return type:

Optional[QgsLayout]

currentPage(self) int

Returns the page visible in the view. This method considers the page at the center of the view as the current visible page.

See also

pageChanged()

Return type:

int

cursorPosChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

customEvent(self, a0: QEvent | None)
deleteItems(self, items: Iterable[QgsLayoutItem])

Delete the specified items.

Parameters:

items (Iterable[QgsLayoutItem])

deleteSelectedItems(self)

Deletes all selected items.

See also

deleteItems()

deltaForKeyEvent(self, event: QKeyEvent | None) QPointF

Returns the delta (in layout coordinates) by which to move items for the given key event.

Parameters:

event (Optional[QKeyEvent])

Return type:

QPointF

deselectAll(self)

Deselects all items in the view.

See also

selectAll()

destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)
disconnectNotify(self, signal: QMetaMethod)
distributeSelectedItems(self, distribution: QgsLayoutAligner.Distribution)

Distributes all selected items using the specified distribution.

Parameters:

distribution (QgsLayoutAligner.Distribution)

dragEnterEvent(self, e: QDragEnterEvent | None)
Parameters:

e (Optional[QDragEnterEvent])

dragLeaveEvent(self, event: QDragLeaveEvent | None)
dragMoveEvent(self, event: QDragMoveEvent | None)
drawBackground(self, painter: QPainter | None, rect: QRectF)
drawForeground(self, painter: QPainter | None, rect: QRectF)
drawFrame(self, a0: QPainter | None)
dropEvent(self, event: QDropEvent | None)
emitZoomLevelChanged(self)
enterEvent(self, a0: QEvent | None)
event(self, event: QEvent | None) bool
eventFilter(self, a0: QObject | None, a1: QEvent | None) bool
focusInEvent(self, event: QFocusEvent | None)
focusNextChild(self) bool
focusNextPrevChild(self, next: bool) bool
focusOutEvent(self, event: QFocusEvent | None)
focusPreviousChild(self) bool
groupSelectedItems(self)

Groups all selected items.

hasItemsInClipboard(self) bool

Returns True if the current clipboard contains layout items.

See also

pasteItems()

Return type:

bool

hideEvent(self, a0: QHideEvent | None)
initPainter(self, painter: QPainter | None)
initStyleOption(self, option: QStyleOptionFrame | None)
inputMethodEvent(self, event: QInputMethodEvent | None)
invertSelection(self)

Inverts the current selection, selecting deselected items and deselecting and selected items.

See also

selectAll()

See also

deselectAll()

isSignalConnected(self, signal: QMetaMethod) bool
itemFocused

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

keyPressEvent(self, event: QKeyEvent | None)
Parameters:

event (Optional[QKeyEvent])

keyReleaseEvent(self, event: QKeyEvent | None)
Parameters:

event (Optional[QKeyEvent])

layoutSet

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

leaveEvent(self, a0: QEvent | None)
lockSelectedItems(self)

Locks any selected items, preventing them from being interacted with by mouse interactions.

See also

unlockAllItems()

lowerSelectedItems(self)

Lowers the selected items down the z-order.

menuProvider(self) QgsLayoutViewMenuProvider | None

Returns the provider for context menus. Returned value may be None if no provider is set.

Return type:

Optional[QgsLayoutViewMenuProvider]

metric(self, a0: QPaintDevice.PaintDeviceMetric) int
mouseDoubleClickEvent(self, event: QMouseEvent | None)
Parameters:

event (Optional[QMouseEvent])

mouseMoveEvent(self, event: QMouseEvent | None)
Parameters:

event (Optional[QMouseEvent])

mousePressEvent(self, event: QMouseEvent | None)
Parameters:

event (Optional[QMouseEvent])

mouseReleaseEvent(self, event: QMouseEvent | None)
Parameters:

event (Optional[QMouseEvent])

moveEvent(self, a0: QMoveEvent | None)
moveSelectedItemsToBottom(self)

Lowers the selected items to the bottom of the z-order.

moveSelectedItemsToTop(self)

Raises the selected items to the top of the z-order.

nativeEvent(self, eventType: QByteArray | bytes | bytearray, message: PyQt5.sip.voidptr | None)
pageChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

paintEvent(self, event: QPaintEvent | None)
Parameters:

event (Optional[QPaintEvent])

pasteItems(self, mode: QgsLayoutView.PasteMode) List[QgsLayoutItem]

Pastes items from clipboard, using the specified mode.

A list of pasted items is returned.

pasteItems(self, layoutPoint: Union[QPointF, QPoint]) -> List[QgsLayoutItem] Pastes items from clipboard, at the specified layoutPoint, in layout units.

A list of pasted items is returned.

Parameters:

mode (QgsLayoutView.PasteMode)

Return type:

List[QgsLayoutItem]

previewMode(self) QgsPreviewEffect.PreviewMode

Returns the preview mode which may be used to modify the view’s appearance. Preview modes are only used if previewModeEnabled() is True.

See also

setPreviewMode()

Return type:

QgsPreviewEffect.PreviewMode

previewModeEnabled(self) bool

Returns True if a preview effect is being used to alter the view’s appearance.

Return type:

bool

pushStatusMessage(self, message: str | None)

Pushes a new status bar message to the view. This causes statusMessage() to be emitted, which should cause the message to appear in the status bar for the parent window.

See also

statusMessage()

Parameters:

message (Optional[str])

raiseSelectedItems(self)

Raises the selected items up the z-order.

receivers(self, signal: PYQT_SIGNAL) int
resizeEvent(self, event: QResizeEvent | None)
Parameters:

event (Optional[QResizeEvent])

resizeSelectedItems(self, resize: QgsLayoutAligner.Resize)

Resizes all selected items using the specified resize mode.

Parameters:

resize (QgsLayoutAligner.Resize)

scaleSafe(self, scale: float)

Scales the view in a safe way, by limiting the acceptable range of the scale applied. The scale parameter specifies the zoom factor to scale the view by.

Parameters:

scale (float)

scrollContentsBy(self, dx: int, dy: int)
Parameters:
  • dx (int)

  • dy (int)

selectAll(self)

Selects all items in the view.

See also

deselectAll()

selectNextItemAbove(self)

Selects the next item above the existing selection, by item z order.

See also

selectAll()

See also

deselectAll()

selectNextItemBelow(self)

Selects the next item below the existing selection, by item z order.

See also

selectAll()

See also

deselectAll()

sender(self) QObject | None
senderSignalIndex(self) int
setCurrentLayout(self, layout: QgsLayout | None)

Sets the current layout to edit in the view.

See also

currentLayout()

See also

layoutSet()

Parameters:

layout (Optional[QgsLayout])

setHorizontalRuler(self, ruler: QgsLayoutRuler | None)

Sets a horizontal ruler to synchronize with the view state.

Parameters:

ruler (Optional[QgsLayoutRuler])

setMenuProvider(self, provider: QgsLayoutViewMenuProvider | None)

Sets a provider for context menus. Ownership of the provider is transferred to the view.

See also

menuProvider()

Parameters:

provider (Optional[QgsLayoutViewMenuProvider])

setPreviewMode(self, mode: QgsPreviewEffect.PreviewMode)

Sets the preview mode which should be used to modify the view’s appearance. Preview modes are only used if previewModeEnabled() is True.

See also

previewMode()

Parameters:

mode (QgsPreviewEffect.PreviewMode)

setPreviewModeEnabled(self, enabled: bool)

Sets whether a preview effect should be used to alter the view’s appearance.

Parameters:

enabled (bool) – Set to True to enable the preview effect on the view.

See also

setPreviewMode()

setSectionLabel(self, label: str | None)

Sets a section label, to display above the first page shown in the view.

Parameters:

label (Optional[str])

setTool(self, tool: QgsLayoutViewTool | None)

Sets the tool currently being used in the view.

See also

unsetTool()

See also

tool()

Parameters:

tool (Optional[QgsLayoutViewTool])

setVerticalRuler(self, ruler: QgsLayoutRuler | None)

Sets a vertical ruler to synchronize with the view state.

Parameters:

ruler (Optional[QgsLayoutRuler])

setViewportMargins(self, left: int, top: int, right: int, bottom: int)
setViewportMargins(self, margins: QMargins) None
setZoomLevel(self, level: float)

Sets the zoom level for the view, where a zoom level of 1.0 corresponds to 100%.

Parameters:

level (float)

setupViewport(self, widget: QWidget | None)
sharedPainter(self) QPainter | None
showEvent(self, event: QShowEvent | None)
statusMessage

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

tabletEvent(self, a0: QTabletEvent | None)
timerEvent(self, a0: QTimerEvent | None)
tool(self) QgsLayoutViewTool | None

Returns the currently active tool for the view.

See also

setTool()

Return type:

Optional[QgsLayoutViewTool]

toolSet

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

ungroupSelectedItems(self)

Ungroups all selected items.

unlockAllItems(self)

Unlocks all locked items in the layout.

unsetTool(self, tool: QgsLayoutViewTool | None)

Unsets the current view tool, if it matches the specified tool.

This is called from destructor of view tools to make sure that the tool won’t be used any more. You don’t have to call it manually, QgsLayoutViewTool takes care of it.

Parameters:

tool (Optional[QgsLayoutViewTool])

updateMicroFocus(self)
viewChanged(self)

Updates associated rulers and other widgets after view extent or zoom has changed. This should be called after calling any of the QGraphicsView base class methods which alter the view’s zoom level or extent, i.e. QGraphicsView.fitInView().

viewportEvent(self, event: QEvent | None) bool
viewportMargins(self) QMargins
viewportSizeHint(self) QSize
visiblePageNumbers(self) List[int]

Returns a list of page numbers for pages which are currently visible in the view.

See also

visiblePages()

Return type:

List[int]

visiblePages(self) List[QgsLayoutItemPage]

Returns a list of page items which are currently visible in the view.

Return type:

List[QgsLayoutItemPage]

wheelEvent(self, event: QWheelEvent | None)
Parameters:

event (Optional[QWheelEvent])

willBeDeleted

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

zoomActual(self)

Zooms to the actual size of the layout.

See also

zoomFull()

See also

zoomIn()

See also

zoomOut()

zoomFull(self)

Zooms the view to the full extent of the layout.

See also

zoomIn()

See also

zoomOut()

See also

zoomActual()

zoomIn(self)

Zooms in to the view by a preset amount.

See also

zoomFull()

See also

zoomOut()

See also

zoomActual()

zoomLevelChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

zoomOut(self)

Zooms out of the view by a preset amount.

See also

zoomFull()

See also

zoomIn()

See also

zoomActual()

zoomWidth(self)

Zooms the view to the full width of the layout.

See also

zoomIn()

See also

zoomOut()

See also

zoomActual()