Class: QgsLayoutView

A graphical widget to display and interact with QgsLayouts.

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

QgsLayoutView

QgsLayoutView

Class Hierarchy

Inheritance diagram of qgis.gui.QgsLayoutView

Base classes

QGraphicsView

QAbstractScrollArea

QFrame

QWidget

QObject

QPaintDevice

class qgis.gui.QgsLayoutView[source]

Bases: QGraphicsView

__init__(parent: QWidget | None = None)

Constructor for QgsLayoutView.

Parameters:

parent (Optional[QWidget] = None)

ClipboardCopy = 1
ClipboardCut = 0
class ClipboardOperation

Bases: int

class PasteMode

Bases: int

PasteModeCenter = 1
PasteModeCursor = 0
PasteModeInPlace = 2
alignSelectedItems(self, alignment: QgsLayoutAligner.Alignment)[source]

Aligns all selected items using the specified alignment.

Parameters:

alignment (QgsLayoutAligner.Alignment)

copyItems(self, items: Iterable[QgsLayoutItem], operation: QgsLayoutView.ClipboardOperation)[source]

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

See also

pasteItems()

Parameters:
copySelectedItems(self, operation: QgsLayoutView.ClipboardOperation)[source]

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

See also

copyItems()

See also

pasteItems()

Parameters:

operation (QgsLayoutView.ClipboardOperation)

currentLayout(self) QgsLayout | None[source]

Returns the current layout associated with the view.

See also

layoutSet()

Return type:

Optional[QgsLayout]

currentPage(self) int[source]

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

signal cursorPosChanged[source]

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.

deleteItems(self, items: Iterable[QgsLayoutItem])[source]

Delete the specified items.

Parameters:

items (Iterable[QgsLayoutItem])

deleteSelectedItems(self)[source]

Deletes all selected items.

See also

deleteItems()

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

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)[source]

Deselects all items in the view.

See also

selectAll()

distributeSelectedItems(self, distribution: QgsLayoutAligner.Distribution)[source]

Distributes all selected items using the specified distribution.

Parameters:

distribution (QgsLayoutAligner.Distribution)

emitZoomLevelChanged(self)[source]
groupSelectedItems(self)[source]

Groups all selected items.

hasItemsInClipboard(self) bool[source]

Returns True if the current clipboard contains layout items.

See also

pasteItems()

Return type:

bool

invertSelection(self)[source]

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

See also

selectAll()

See also

deselectAll()

signal itemFocused[source]

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.

signal layoutSet[source]

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.

lockSelectedItems(self)[source]

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

See also

unlockAllItems()

lowerSelectedItems(self)[source]

Lowers the selected items down the z-order.

menuProvider(self) QgsLayoutViewMenuProvider | None[source]

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

Return type:

Optional[QgsLayoutViewMenuProvider]

moveSelectedItemsToBottom(self)[source]

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

moveSelectedItemsToTop(self)[source]

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

signal pageChanged[source]

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.

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[source]

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[source]

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

Return type:

bool

pushStatusMessage(self, message: str | None)[source]

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)[source]

Raises the selected items up the z-order.

resizeSelectedItems(self, resize: QgsLayoutAligner.Resize)[source]

Resizes all selected items using the specified resize mode.

Parameters:

resize (QgsLayoutAligner.Resize)

scaleSafe(self, scale: float)[source]

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)

selectAll(self)[source]

Selects all items in the view.

See also

deselectAll()

selectNextItemAbove(self)[source]

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

See also

selectAll()

See also

deselectAll()

selectNextItemBelow(self)[source]

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

See also

selectAll()

See also

deselectAll()

setCurrentLayout(self, layout: QgsLayout | None)[source]

Sets the current layout to edit in the view.

See also

currentLayout()

See also

layoutSet()

Parameters:

layout (Optional[QgsLayout])

setHorizontalRuler(self, ruler: QgsLayoutRuler | None)[source]

Sets a horizontal ruler to synchronize with the view state.

Parameters:

ruler (Optional[QgsLayoutRuler])

setMenuProvider(self, provider: QgsLayoutViewMenuProvider | None)[source]

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)[source]

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)[source]

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)[source]

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

Parameters:

label (Optional[str])

setTool(self, tool: QgsLayoutViewTool | None)[source]

Sets the tool currently being used in the view.

See also

unsetTool()

See also

tool()

Parameters:

tool (Optional[QgsLayoutViewTool])

setVerticalRuler(self, ruler: QgsLayoutRuler | None)[source]

Sets a vertical ruler to synchronize with the view state.

Parameters:

ruler (Optional[QgsLayoutRuler])

setZoomLevel(self, level: float)[source]

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

Parameters:

level (float)

signal statusMessage[source]

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.

tool(self) QgsLayoutViewTool | None[source]

Returns the currently active tool for the view.

See also

setTool()

Return type:

Optional[QgsLayoutViewTool]

signal toolSet[source]

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.

ungroupSelectedItems(self)[source]

Ungroups all selected items.

unlockAllItems(self)[source]

Unlocks all locked items in the layout.

unsetTool(self, tool: QgsLayoutViewTool | None)[source]

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])

viewChanged(self)[source]

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().

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]

signal willBeDeleted[source]

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.

zoomActual(self)[source]

Zooms to the actual size of the layout.

See also

zoomFull()

See also

zoomIn()

See also

zoomOut()

zoomFull(self)[source]

Zooms the view to the full extent of the layout.

See also

zoomIn()

See also

zoomOut()

See also

zoomActual()

zoomIn(self)[source]

Zooms in to the view by a preset amount.

See also

zoomFull()

See also

zoomOut()

See also

zoomActual()

signal zoomLevelChanged[source]

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.

zoomOut(self)[source]

Zooms out of the view by a preset amount.

See also

zoomFull()

See also

zoomIn()

See also

zoomActual()

zoomWidth(self)[source]

Zooms the view to the full width of the layout.

See also

zoomIn()

See also

zoomOut()

See also

zoomActual()