Class: QgsLayout

class qgis.core.QgsLayout

Bases: PyQt5.QtWidgets.QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoObjectInterface

Base class for layouts, which can contain items such as maps, labels, scalebars, etc.

While the raw QGraphicsScene API can be used to render the contents of a QgsLayout to a QPainter, it is recommended to instead use a QgsLayoutExporter to handle rendering layouts instead. QgsLayoutExporter automatically takes care of the intracacies of preparing the layout and paint devices for correct exports, respecting various user settings such as the layout context DPI.

QgsLayout(project: QgsProject) Construct a new layout linked to the specified project.

If the layout is a “new” layout (as opposed to a layout which will restore a previous state from XML) then initializeDefaults() should be called on the new layout.

Methods

accept

Accepts the specified style entity visitor, causing it to visit all style entities associated with the layout.

addItemsFromXml

Add items from an XML representation to the layout.

addLayoutItem

Adds an item to the layout.

addMultiFrame

Adds a multiFrame to the layout.

childEvent

clear

Clears the layout.

clone

Creates a clone of the layout.

connectNotify

contextMenuEvent

convertFromLayoutUnits

Converts a length measurement from the layout's native units to a specified target unit.

convertToLayoutUnits

Converts a measurement into the layout's native units.

createCommand

param text:

createExpressionContext

Creates an expression context relating to the layout's current state.

customEvent

customProperties

Returns list of keys stored in custom properties for the layout.

customProperty

Read a custom property from the layout.

deselectAll

Clears any selected items in the layout.

disconnectNotify

dragEnterEvent

dragLeaveEvent

dragMoveEvent

drawBackground

drawForeground

dropEvent

event

eventFilter

focusInEvent

focusNextPrevChild

focusOutEvent

gridSettings

Returns a reference to the layout's grid settings, which stores settings relating to grid appearance, spacing and offsets.

groupItems

Creates a new group from a list of layout items and adds the group to the layout.

guides

Returns a reference to the layout's guide collection, which manages page snap guides.

helpEvent

initializeDefaults

Initializes an empty layout, e.g. by adding a default page to the layout.

inputMethodEvent

isSignalConnected

itemById

Returns a layout item given its id.

itemByTemplateUuid

Returns the layout item with matching template uuid unique identifier, or None if a matching item could not be found.

itemByUuid

Returns the layout item with matching uuid unique identifier, or None if a matching item could not be found.

itemsModel

Returns the items model attached to the layout.

keyPressEvent

keyReleaseEvent

layoutBounds

Calculates the bounds of all non-gui items in the layout.

layoutItemAt

Returns the topmost layout item at a specified position.

loadFromTemplate

Load a layout template document.

lowerItem

Lowers an item down the z-order.

mouseDoubleClickEvent

mouseMoveEvent

mousePressEvent

mouseReleaseEvent

moveItemToBottom

Lowers an item down to the bottom of the z-order.

moveItemToTop

Raises an item up to the top of the z-order.

multiFrameByUuid

Returns the layout multiframe with matching uuid unique identifier, or None if a matching multiframe could not be found.

multiFrames

Returns a list of multi frames contained in the layout.

pageCollection

Returns a pointer to the layout's page collection, which stores and manages page items in the layout.

pageItemBounds

Returns the bounding box of the items contained on a specified page.

project

The project associated with the layout.

raiseItem

Raises an item up the z-order.

readXml

Sets the collection's state from a DOM element.

receivers

referenceMap

Returns the map item which will be used to generate corresponding world files when the layout is exported.

refresh

Forces the layout, and all items contained within it, to refresh.

reloadSettings

Refreshes the layout when global layout related options change.

removeCustomProperty

Remove a custom property from the layout.

removeLayoutItem

Removes an item from the layout.

removeMultiFrame

Removes a multiFrame from the layout (but does not delete it).

renderContext

Returns a reference to the layout's render context, which stores information relating to the current rendering settings for the layout.

reportContext

Returns a reference to the layout's report context, which stores information relating to the current reporting context for the layout.

saveAsTemplate

Saves the layout as a template at the given file path.

selectedLayoutItems

Returns list of selected layout items.

sender

senderSignalIndex

setCustomProperty

Set a custom property for the layout.

setReferenceMap

Sets the map item which will be used to generate corresponding world files when the layout is exported.

setSelectedItem

Clears any selected items and sets item as the current selection.

setUnits

Sets the native measurement units for the layout.

snapper

Returns a reference to the layout's snapper, which stores handles layout snap grids and lines and snapping points to the nearest matching point.

timerEvent

undoStack

Returns a pointer to the layout's undo stack, which manages undo/redo states for the layout and it's associated objects.

ungroupItems

Ungroups items by removing them from an item group and removing the group from the layout.

units

Returns the native units for the layout.

updateBounds

Updates the scene bounds of the layout.

updateZValues

Resets the z-values of items based on their position in the internal z order list.

wheelEvent

writeXml

Returns the layout's state encapsulated in a DOM element.

Signals

backgroundTaskCountChanged

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

changed

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

itemAdded

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

refreshed

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

selectedItemChanged

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

variablesChanged

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

Attributes

UndoLayoutDpi

UndoNone

ZGrid

ZGuide

ZItem

ZMouseHandles

ZPage

ZSmartGuide

ZSnapIndicator

ZViewTool

class UndoCommand

Bases: int

UndoLayoutDpi = 0
UndoNone = -1
ZGrid = 9997
ZGuide = 9998
ZItem = 1
ZMouseHandles = 10000
ZPage = 0
ZSmartGuide = 9999
ZSnapIndicator = 10002
class ZValues

Bases: int

ZViewTool = 10001
accept(self, visitor: QgsStyleEntityVisitorInterface) bool

Accepts the specified style entity visitor, causing it to visit all style entities associated with the layout.

Returns True if the visitor should continue visiting other objects, or False if visiting should be canceled.

New in version 3.10.

Parameters:

visitor (QgsStyleEntityVisitorInterface) –

Return type:

bool

addItemsFromXml(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext, position: QPointF | QPoint = None, pasteInPlace: bool = False) List[QgsLayoutItem]

Add items from an XML representation to the layout. Used for project file reading and pasting items from clipboard.

The position argument is optional, and if it is not specified the items will be restored to their original position from the XML serialization. If specified, the items will be positioned such that the top-left bounds of all added items is located at this position.

The pasteInPlace argument determines whether the serialized position should be respected, but remapped to the origin of the page corresponding to the page at position.

A list of the newly added items is returned.

Parameters:
  • parentElement (QDomElement) –

  • document (QDomDocument) –

  • context (QgsReadWriteContext) –

  • position (Union[QPointF) –

  • pasteInPlace (bool = False) –

Return type:

List[QgsLayoutItem]

addLayoutItem(self, item: QgsLayoutItem)

Adds an item to the layout. This should be called instead of the base class addItem() method. Ownership of the item is transferred to the layout.

Parameters:

item (QgsLayoutItem) –

addMultiFrame(self, multiFrame: QgsLayoutMultiFrame)

Adds a multiFrame to the layout. The object is owned by the layout until removeMultiFrame() is called.

See also

multiFrames()

Parameters:

multiFrame (QgsLayoutMultiFrame) –

backgroundTaskCountChanged

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

changed

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

childEvent(self, QChildEvent)
clear(self)

Clears the layout.

Calling this method removes all items and pages from the layout.

clone(self) QgsLayout

Creates a clone of the layout. Ownership of the return layout is transferred to the caller.

Return type:

QgsLayout

connectNotify(self, QMetaMethod)
contextMenuEvent(self, QGraphicsSceneContextMenuEvent)
convertFromLayoutUnits(self, length: float, unit: Qgis.LayoutUnit) QgsLayoutMeasurement

Converts a length measurement from the layout’s native units to a specified target unit.

Returns:

length of measurement in specified units

See also

units()

convertFromLayoutUnits(self, size: QSizeF, unit: Qgis.LayoutUnit) -> QgsLayoutSize Converts a size from the layout’s native units to a specified target unit.

Returns:

size of measurement in specified units

See also

units()

convertFromLayoutUnits(self, point: Union[QPointF, QPoint], unit: Qgis.LayoutUnit) -> QgsLayoutPoint Converts a point from the layout’s native units to a specified target unit.

Return type:

QgsLayoutMeasurement

Returns:

point in specified units

See also

units()

Parameters:
convertToLayoutUnits(self, measurement: QgsLayoutMeasurement) float

Converts a measurement into the layout’s native units.

Returns:

length of measurement in layout units

See also

units()

convertToLayoutUnits(self, size: QgsLayoutSize) -> QSizeF Converts a size into the layout’s native units.

Returns:

size of measurement in layout units

See also

units()

convertToLayoutUnits(self, point: QgsLayoutPoint) -> QPointF Converts a point into the layout’s native units.

Return type:

float

Returns:

point in layout units

See also

units()

Parameters:

measurement (QgsLayoutMeasurement) –

createCommand(self, text: str, id: int = 0, parent: QUndoCommand = None) QgsAbstractLayoutUndoCommand
Parameters:
  • text (str) –

  • id (int = 0) –

  • parent (QUndoCommand = None) –

Return type:

QgsAbstractLayoutUndoCommand

createExpressionContext(self) QgsExpressionContext

Creates an expression context relating to the layout’s current state. The context includes scopes for global, project, layout and layout context properties.

Return type:

QgsExpressionContext

customEvent(self, QEvent)
customProperties(self) List[str]

Returns list of keys stored in custom properties for the layout.

See also

customProperty()

Return type:

List[str]

customProperty(self, key: str, defaultValue: Any = None) Any

Read a custom property from the layout.

Parameters:
  • key (str) – property key

  • defaultValue (Any = None) – default value to return if property with matching key does not exist

Return type:

Any

Returns:

value of matching property

deselectAll(self)

Clears any selected items in the layout.

Call this method rather than QGraphicsScene.clearSelection, as the latter does not correctly emit signals to allow the layout’s model to update.

disconnectNotify(self, QMetaMethod)
dragEnterEvent(self, QGraphicsSceneDragDropEvent)
dragLeaveEvent(self, QGraphicsSceneDragDropEvent)
dragMoveEvent(self, QGraphicsSceneDragDropEvent)
drawBackground(self, QPainter, QRectF)
drawForeground(self, QPainter, QRectF)
dropEvent(self, QGraphicsSceneDragDropEvent)
event(self, QEvent) bool
eventFilter(self, QObject, QEvent) bool
focusInEvent(self, QFocusEvent)
focusNextPrevChild(self, bool) bool
focusOutEvent(self, QFocusEvent)
gridSettings(self) QgsLayoutGridSettings

Returns a reference to the layout’s grid settings, which stores settings relating to grid appearance, spacing and offsets.

Return type:

QgsLayoutGridSettings

groupItems(self, items: Iterable[QgsLayoutItem]) QgsLayoutItemGroup

Creates a new group from a list of layout items and adds the group to the layout. If grouping was not possible, None will be returned.

See also

ungroupItems()

Parameters:

items (Iterable[QgsLayoutItem]) –

Return type:

QgsLayoutItemGroup

guides(self) QgsLayoutGuideCollection

Returns a reference to the layout’s guide collection, which manages page snap guides.

Return type:

QgsLayoutGuideCollection

helpEvent(self, QGraphicsSceneHelpEvent)
initializeDefaults(self)

Initializes an empty layout, e.g. by adding a default page to the layout. This should be called after creating a new layout.

inputMethodEvent(self, QInputMethodEvent)
isSignalConnected(self, QMetaMethod) bool
itemAdded

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

itemById(self, id: str) QgsLayoutItem

Returns a layout item given its id. Since item IDs are not necessarely unique, this function returns the first matching item found.

See also

itemByUuid()

Parameters:

id (str) –

Return type:

QgsLayoutItem

itemByTemplateUuid(self, uuid: str) QgsLayoutItem

Returns the layout item with matching template uuid unique identifier, or None if a matching item could not be found. Unlike itemByUuid(), this method ONLY checks template UUIDs for a match.

Template UUIDs are valid only for items which have been added to an existing layout from a template. In this case the template UUID is the original item UUID at the time the template was created, vs the item’s uuid() which returns the current instance of the item’s unique identifier.

Note that template UUIDs are only available while a layout is being restored from XML.

See also

itemByUuid()

See also

itemById()

Parameters:

uuid (str) –

Return type:

QgsLayoutItem

itemByUuid(self, uuid: str, includeTemplateUuids: bool = False) QgsLayoutItem

Returns the layout item with matching uuid unique identifier, or None if a matching item could not be found.

If includeTemplateUuids is True, then item’s template UUID will also be tested when trying to match the uuid. This may differ from the item’s UUID for items which have been added to an existing layout from a template. In this case the template UUID returns the original item UUID at the time the template was created, vs the item’s uuid() which returns the current instance of the item’s unique identifier. Note that template UUIDs are only available while a layout is being restored from XML.

See also

itemById()

Parameters:
  • uuid (str) –

  • includeTemplateUuids (bool = False) –

Return type:

QgsLayoutItem

itemsModel(self) QgsLayoutModel

Returns the items model attached to the layout.

Return type:

QgsLayoutModel

keyPressEvent(self, QKeyEvent)
keyReleaseEvent(self, QKeyEvent)
layoutBounds(self, ignorePages: bool = False, margin: float = 0) QRectF

Calculates the bounds of all non-gui items in the layout. Ignores snap lines, mouse handles and other cosmetic items.

Parameters:
  • ignorePages (bool = False) – set to True to ignore page items

  • margin (float = 0) – optional marginal (in percent, e.g., 0.05 = 5% ) to add around items

Return type:

QRectF

Returns:

layout bounds, in layout units.

See also

pageItemBounds()

layoutItemAt(self, position: QPointF | QPoint, ignoreLocked: bool = False, searchTolerance: float = 0) QgsLayoutItem

Returns the topmost layout item at a specified position. Ignores paper items. If ignoreLocked is set to True any locked items will be ignored. Since QGIS 3.34 the searchTolerance parameter was added, which can be used to specify a search tolerance in layout units.

layoutItemAt(self, position: Union[QPointF, QPoint], belowItem: QgsLayoutItem, ignoreLocked: bool = False, searchTolerance: float = 0) -> QgsLayoutItem Returns the topmost layout item at a specified position which is below a specified item. Ignores paper items. If ignoreLocked is set to True any locked items will be ignored. Since QGIS 3.34 the searchTolerance parameter was added, which can be used to specify a search tolerance in layout units.

Parameters:
  • position (Union[QPointF) –

  • ignoreLocked (bool = False) –

  • searchTolerance (float = 0) –

Return type:

QgsLayoutItem

loadFromTemplate(self, document: QDomDocument, context: QgsReadWriteContext, clearExisting: bool = True) Tuple[List[QgsLayoutItem], bool]

Load a layout template document.

By default this method will clear all items from the existing layout and real all layout settings from the template. Setting clearExisting to False will only add new items from the template, without overwriting the existing items or layout settings.

If ok is specified, it will be set to True if the load was successful.

Returns a list of loaded items.

Parameters:
  • document (QDomDocument) –

  • context (QgsReadWriteContext) –

  • clearExisting (bool = True) –

Return type:

Tuple[List[QgsLayoutItem], bool]

lowerItem(self, item: QgsLayoutItem, deferUpdate: bool = False) bool

Lowers an item down the z-order. Returns True if the item was successfully lowered.

If deferUpdate is True, the scene will not be visibly updated to reflect the new stacking order. This allows multiple raiseItem() calls to be made in sequence without the cost of updating the scene for each one.

See also

raiseItem()

See also

updateZValues()

Parameters:
Return type:

bool

mouseDoubleClickEvent(self, QGraphicsSceneMouseEvent)
mouseMoveEvent(self, QGraphicsSceneMouseEvent)
mousePressEvent(self, QGraphicsSceneMouseEvent)
mouseReleaseEvent(self, QGraphicsSceneMouseEvent)
moveItemToBottom(self, item: QgsLayoutItem, deferUpdate: bool = False) bool

Lowers an item down to the bottom of the z-order. Returns True if the item was successfully lowered. If deferUpdate is True, the scene will not be visibly updated to reflect the new stacking order. This allows multiple raiseItem() calls to be made in sequence without the cost of updating the scene for each one.

See also

moveItemToTop()

See also

updateZValues()

Parameters:
Return type:

bool

moveItemToTop(self, item: QgsLayoutItem, deferUpdate: bool = False) bool

Raises an item up to the top of the z-order. Returns True if the item was successfully raised.

If deferUpdate is True, the scene will not be visibly updated to reflect the new stacking order. This allows multiple raiseItem() calls to be made in sequence without the cost of updating the scene for each one.

See also

updateZValues()

Parameters:
Return type:

bool

multiFrameByUuid(self, uuid: str, includeTemplateUuids: bool = False) QgsLayoutMultiFrame

Returns the layout multiframe with matching uuid unique identifier, or None if a matching multiframe could not be found.

If includeTemplateUuids is True, then the multiframe’s QgsLayoutMultiFrame.templateUuid() will also be tested when trying to match the uuid. Template UUIDs are valid only for items which have been added to an existing layout from a template. In this case the template UUID is the original item UUID at the time the template was created, vs the item’s uuid() which returns the current instance of the item’s unique identifier. Note that template UUIDs are only available while a layout is being restored from XML.

See also

itemByUuid()

Parameters:
  • uuid (str) –

  • includeTemplateUuids (bool = False) –

Return type:

QgsLayoutMultiFrame

multiFrames(self) List[QgsLayoutMultiFrame]

Returns a list of multi frames contained in the layout.

See also

addMultiFrame()

Return type:

List[QgsLayoutMultiFrame]

pageCollection(self) QgsLayoutPageCollection

Returns a pointer to the layout’s page collection, which stores and manages page items in the layout.

Return type:

QgsLayoutPageCollection

pageItemBounds(self, page: int, visibleOnly: bool = False) QRectF

Returns the bounding box of the items contained on a specified page. A page number of 0 represents the first page in the layout.

Set visibleOnly to True to only include visible items.

The returned bounds are in layout units.

See also

layoutBounds()

Parameters:
  • page (int) –

  • visibleOnly (bool = False) –

Return type:

QRectF

project(self) QgsProject

The project associated with the layout. Used to get access to layers, map themes, relations and various other bits. It is never None.

Return type:

QgsProject

raiseItem(self, item: QgsLayoutItem, deferUpdate: bool = False) bool

Raises an item up the z-order. Returns True if the item was successfully raised.

If deferUpdate is True, the scene will not be visibly updated to reflect the new stacking order. This allows multiple raiseItem() calls to be made in sequence without the cost of updating the scene for each one.

See also

lowerItem()

See also

updateZValues()

Parameters:
Return type:

bool

readXml(self, layoutElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool

Sets the collection’s state from a DOM element. layoutElement is the DOM node corresponding to the layout.

See also

writeXml()

Parameters:
  • layoutElement (QDomElement) –

  • document (QDomDocument) –

  • context (QgsReadWriteContext) –

Return type:

bool

receivers(self, PYQT_SIGNAL) int
referenceMap(self) QgsLayoutItemMap

Returns the map item which will be used to generate corresponding world files when the layout is exported. If no map was explicitly set via setReferenceMap(), the largest map in the layout will be returned (or None if there are no maps in the layout).

Return type:

QgsLayoutItemMap

refresh(self)

Forces the layout, and all items contained within it, to refresh. For instance, this causes maps to redraw and rebuild cached images, html items to reload their source url, and attribute tables to refresh their contents. Calling this also triggers a recalculation of all data defined attributes within the layout.

See also

refreshed()

refreshed

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

reloadSettings(self)

Refreshes the layout when global layout related options change.

removeCustomProperty(self, key: str)

Remove a custom property from the layout.

Parameters:

key (str) – property key

See also

customProperty()

removeLayoutItem(self, item: QgsLayoutItem)

Removes an item from the layout. This should be called instead of the base class removeItem() method. The item will also be deleted.

Parameters:

item (QgsLayoutItem) –

removeMultiFrame(self, multiFrame: QgsLayoutMultiFrame)

Removes a multiFrame from the layout (but does not delete it).

See also

addMultiFrame()

See also

multiFrames()

Parameters:

multiFrame (QgsLayoutMultiFrame) –

renderContext(self) QgsLayoutRenderContext

Returns a reference to the layout’s render context, which stores information relating to the current rendering settings for the layout.

Return type:

QgsLayoutRenderContext

reportContext(self) QgsLayoutReportContext

Returns a reference to the layout’s report context, which stores information relating to the current reporting context for the layout.

Return type:

QgsLayoutReportContext

saveAsTemplate(self, path: str, context: QgsReadWriteContext) bool

Saves the layout as a template at the given file path. Returns True if save was successful.

Parameters:
Return type:

bool

selectedItemChanged

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

selectedLayoutItems(self, includeLockedItems: bool = True) List[QgsLayoutItem]

Returns list of selected layout items.

If includeLockedItems is set to True, then locked items will also be included in the returned list.

Parameters:

includeLockedItems (bool = True) –

Return type:

List[QgsLayoutItem]

sender(self) QObject
senderSignalIndex(self) int
setCustomProperty(self, key: str, value: Any)

Set a custom property for the layout.

Parameters:
  • key (str) – property key. If a property with the same key already exists it will be overwritten.

  • value (Any) – property value

See also

customProperty()

setReferenceMap(self, map: QgsLayoutItemMap)

Sets the map item which will be used to generate corresponding world files when the layout is exported.

See also

referenceMap()

Parameters:

map (QgsLayoutItemMap) –

setSelectedItem(self, item: QgsLayoutItem)

Clears any selected items and sets item as the current selection.

Parameters:

item (QgsLayoutItem) –

setUnits(self, units: Qgis.LayoutUnit)

Sets the native measurement units for the layout. These also form the default unit for measurements for the layout.

See also

units()

Parameters:

units (Qgis.LayoutUnit) –

snapper(self) QgsLayoutSnapper

Returns a reference to the layout’s snapper, which stores handles layout snap grids and lines and snapping points to the nearest matching point.

Return type:

QgsLayoutSnapper

timerEvent(self, QTimerEvent)
undoStack(self) QgsLayoutUndoStack

Returns a pointer to the layout’s undo stack, which manages undo/redo states for the layout and it’s associated objects.

Return type:

QgsLayoutUndoStack

ungroupItems(self, group: QgsLayoutItemGroup) List[QgsLayoutItem]

Ungroups items by removing them from an item group and removing the group from the layout. Child items will remain in the layout and will not be deleted.

Returns a list of the items removed from the group, or an empty list if ungrouping was not successful.

See also

groupItems()

Parameters:

group (QgsLayoutItemGroup) –

Return type:

List[QgsLayoutItem]

units(self) Qgis.LayoutUnit

Returns the native units for the layout.

See also

setUnits()

Return type:

Qgis.LayoutUnit

updateBounds(self)

Updates the scene bounds of the layout.

updateZValues(self, addUndoCommands: bool = True)

Resets the z-values of items based on their position in the internal z order list. This should be called after any stacking changes which deferred z-order updates.

Parameters:

addUndoCommands (bool = True) –

variablesChanged

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

wheelEvent(self, QGraphicsSceneWheelEvent)
writeXml(self, document: QDomDocument, context: QgsReadWriteContext) QDomElement

Returns the layout’s state encapsulated in a DOM element.

See also

readXml()

Parameters:
Return type:

QDomElement