Class: QgsLayoutItem

class qgis.core.QgsLayoutItem

Bases: QgsLayoutObject, PyQt5.QtWidgets.QGraphicsRectItem, QgsLayoutUndoObjectInterface

Base class for graphical items within a QgsLayout.

New in version 3.0.

QgsLayoutItem(layout: QgsLayout, manageZValue: bool = True) Constructor for QgsLayoutItem, with the specified parent layout.

If manageZValue is True, the z-Value of this item will be managed by the layout. Generally this is the desired behavior.

Methods

accept

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

adjustPointForReferencePosition

Adjusts the specified point at which a reference position of the item sits and returns the top left corner of the item, if reference point were placed at the specified position.

applyDataDefinedSize

Applies any present data defined size overrides to the specified layout size.

applyItemSizeConstraint

Applies any item-specific size constraint handling to a given targetSize in layout units.

attemptMove

Attempts to move the item to a specified point.

attemptMoveBy

Attempts to shift the item's position by a specified deltaX and deltaY, in layout units.

attemptResize

Attempts to resize the item to a specified target size.

attemptSetSceneRect

Attempts to update the item's position and size to match the passed rect in layout coordinates.

backgroundColor

Returns the background color for this item.

beginCommand

Starts new undo command for this item.

blendMode

Returns the item's composition blending mode.

cancelCommand

Cancels the current item command and discards it.

childEvent

cleanup

Called just before a batch of items are deleted, allowing them to run cleanup tasks.

clipPath

Returns the clipping path generated by this item, in layout coordinates.

connectNotify

containsAdvancedEffects

Returns True if the item contains contents with blend modes or transparency effects which can only be reproduced by rastering the item.

contextMenuEvent

createCommand

param text:

createExpressionContext

rtype:

QgsExpressionContext

customEvent

disconnectNotify

displayName

Gets item display name.

dragEnterEvent

dragLeaveEvent

dragMoveEvent

draw

Draws the item's contents using the specified item render context.

drawBackground

Draws the background for the item.

drawDebugRect

Draws a debugging rectangle of the item's current bounds within the specified painter.

drawFrame

Draws the frame around the item.

dropEvent

endCommand

Completes the current item command and push it onto the layout's undo stack.

estimatedFrameBleed

Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.

excludeFromExports

Returns whether the item should be excluded from layout exports and prints.

exportLayerBehavior

Returns the behavior of this item during exporting to layered exports (e.g. SVG).

exportLayerDetails

Returns the details for the specified current export layer.

finalizeRestoreFromXml

Called after all pending items have been restored from XML.

fixedSize

Returns the fixed size of the item, if applicable, or an empty size if item can be freely resized.

focusInEvent

focusOutEvent

frameEnabled

Returns True if the item includes a frame.

frameJoinStyle

Returns the join style used for drawing the item's frame.

framePath

Returns the path to use when drawing the item's frame or background.

frameStrokeColor

Returns the frame's stroke color.

frameStrokeWidth

Returns the frame's stroke width.

hasBackground

Returns True if the item has a background.

hoverEnterEvent

hoverLeaveEvent

hoverMoveEvent

icon

Returns the item's icon.

id

Returns the item's ID name.

inputMethodEvent

inputMethodQuery

invalidateCache

Forces a deferred update of any cached image the item uses.

isGroupMember

Returns True if the item is part of a QgsLayoutItemGroup group.

isLocked

Returns True if the item is locked, and cannot be interacted with using the mouse.

isSignalConnected

itemChange

itemFlags

Returns the item's flags, which indicate how the item behaves.

itemOpacity

Returns the item's opacity.

itemRotation

Returns the current rotation for the item, in degrees clockwise.

keyPressEvent

keyReleaseEvent

minimumSize

Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely resized.

mouseDoubleClickEvent

mouseMoveEvent

mousePressEvent

mouseReleaseEvent

moveContent

Moves the content of the item, by a specified dx and dy in layout units.

nextExportPart

Moves to the next export part for a multi-layered export item, during a multi-layered export.

numberExportLayers

Returns the number of layers that this item requires for exporting during layered exports (e.g. SVG).

page

Returns the page the item is currently on, with the first page returning 0.

pagePos

Returns the item's position (in layout units) relative to the top left corner of its current page.

pagePositionWithUnits

Returns the item's position (in item units) relative to the top left corner of its current page.

paint

Handles preparing a paint surface for the layout item and painting the item's content.

parentGroup

Returns the item's parent group, if the item is part of a QgsLayoutItemGroup group.

positionAtReferencePoint

Returns the current position (in layout units) of a reference point for the item.

positionWithUnits

Returns the item's current position, including units.

prepareGeometryChange

readObjectPropertiesFromElement

Sets object properties from a DOM element

readPropertiesFromElement

Sets item state from a DOM element.

readXml

Sets the item state from a DOM element.

receivers

rectWithFrame

Returns the item's rectangular bounds, including any bleed caused by the item's frame.

redraw

Triggers a redraw (update) of the item.

referencePoint

Returns the reference point for positioning of the layout item.

refresh

Refreshes the item, causing a recalculation of any property overrides and recalculation of its position and size.

refreshBackgroundColor

Refresh item's background color, considering data defined colors.

refreshBlendMode

Refresh item's blend mode, considering data defined blend mode.

refreshDataDefinedProperty

Refreshes a data defined property for the item by reevaluating the property's value and redrawing the item with this new value.

refreshFrame

Refresh item's frame, considering data defined colors and frame size.

refreshItemPosition

Refreshes an item's position by rechecking it against any possible overrides such as data defined positioning.

refreshItemRotation

Refreshes an item's rotation by rechecking it against any possible overrides such as data defined rotation.

refreshItemSize

Refreshes an item's size by rechecking it against any possible item fixed or minimum sizes.

refreshOpacity

Refresh item's opacity, considering data defined opacity.

requiresRasterization

Returns True if the item is drawn in such a way that forces the whole layout to be rasterized when exporting to vector formats.

rotateItem

Rotates the item by a specified angle in degrees clockwise around a specified reference point.

sceneEvent

sceneEventFilter

sender

senderSignalIndex

setBackgroundColor

Sets the background color for this item.

setBackgroundEnabled

Sets whether this item has a background drawn under it or not.

setBlendMode

Sets the item's composition blending mode.

setExcludeFromExports

Sets whether the item should be excluded from layout exports and prints.

setFixedSize

Sets a fixed size for the layout item, which prevents it from being freely resized.

setFrameEnabled

Sets whether this item has a frame drawn around it or not.

setFrameJoinStyle

Sets the join style used when drawing the item's frame.

setFrameStrokeColor

Sets the frame stroke color.

setFrameStrokeWidth

Sets the frame stroke width.

setId

Set the item's id name.

setItemOpacity

Sets the item's opacity.

setItemRotation

Sets the layout item's rotation, in degrees clockwise.

setLocked

Sets whether the item is locked, preventing mouse interactions with the item.

setMinimumSize

Sets the minimum allowed size for the layout item.

setMoveContentPreviewOffset

Sets temporary offset for the item, by a specified dx and dy in layout units.

setParentGroup

Sets the item's parent group.

setReferencePoint

Sets the reference point for positioning of the layout item.

setSelected

Sets whether the item should be selected.

setVisibility

Sets whether the item is visible.

shouldDrawItem

Returns whether the item should be drawn in the current context.

sizeWithUnits

Returns the item's current size, including units.

startLayeredExport

Starts a multi-layer export operation.

stopLayeredExport

Stops a multi-layer export operation.

timerEvent

topLeftToReferencePoint

Returns the position for the reference point of the item, if the top-left of the item was placed at the specified point.

type

Returns a unique graphics item type identifier.

updateMicroFocus

uuid

Returns the item identification string.

wheelEvent

writeObjectPropertiesToElement

Stores object properties within an XML DOM element.

writePropertiesToElement

Stores item state within an XML DOM element.

writeXml

Stores the item state in a DOM element.

zoomContent

Zooms content of item.

Signals

backgroundTaskCountChanged

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

clipPathChanged

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

frameChanged

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

lockChanged

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

rotationChanged

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

sizePositionChanged

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

Attributes

CanGroupWithAnyOtherItem

CanGroupWithItemsOfSameType

FlagOverridesPaint

FlagProvidesClipPath

ItemContainsSubLayers

LowerLeft

LowerMiddle

LowerRight

Middle

MiddleLeft

MiddleRight

MustPlaceInOwnLayer

UndoArrowHeadFillColor

UndoArrowHeadStrokeColor

UndoArrowHeadWidth

UndoArrowStrokeWidth

UndoAtlasMargin

UndoBackgroundColor

UndoCustomCommand

UndoGridFramePenColor

UndoIncrementalMove

UndoIncrementalResize

UndoLabelFont

UndoLabelFontColor

UndoLabelMargin

UndoLabelText

UndoLegendBoxSpace

UndoLegendColumnCount

UndoLegendColumnSpace

UndoLegendFontColor

UndoLegendGroupFont

UndoLegendGroupIndent

UndoLegendGroupSpace

UndoLegendIconSymbolSpace

UndoLegendItemFont

UndoLegendLayerFont

UndoLegendLayerSpace

UndoLegendLineSpacing

UndoLegendMaxSymbolSize

UndoLegendMinSymbolSize

UndoLegendRasterStrokeColor

UndoLegendRasterStrokeWidth

UndoLegendSubgroupIndent

UndoLegendSymbolHeight

UndoLegendSymbolSpace

UndoLegendSymbolWidth

UndoLegendText

UndoLegendTitleFont

UndoLegendTitleSpaceBottom

UndoLegendWmsLegendHeight

UndoLegendWmsLegendWidth

UndoMapAnnotationDistance

UndoMapGridAnnotationFontColor

UndoMapGridFrameFill1Color

UndoMapGridFrameFill2Color

UndoMapGridIntervalRange

UndoMapGridLineSymbol

UndoMapGridMarkerSymbol

UndoMapLabelMargin

UndoMapRotation

UndoNodeMove

UndoNone

UndoOpacity

UndoOverviewStyle

UndoPictureFillColor

UndoPictureNorthOffset

UndoPictureRotation

UndoPictureStrokeColor

UndoPictureStrokeWidth

UndoRotation

UndoScaleBarBoxContentSpace

UndoScaleBarFillColor

UndoScaleBarFillColor2

UndoScaleBarFontColor

UndoScaleBarHeight

UndoScaleBarLabelBarSize

UndoScaleBarLineWidth

UndoScaleBarMapUnitsSegment

UndoScaleBarSegmentSize

UndoScaleBarSegments

UndoScaleBarSegmentsLeft

UndoScaleBarStrokeColor

UndoScaleBarSubdivisions

UndoScaleBarSubdivisionsHeight

UndoScaleBarUnitText

UndoSetId

UndoShapeCornerRadius

UndoShapeStyle

UndoStrokeColor

UndoStrokeWidth

UndoZoomContent

UpperLeft

UpperMiddle

UpperRight

CanGroupWithAnyOtherItem = 0
CanGroupWithItemsOfSameType = 1
class ExportLayerBehavior

Bases: int

class ExportLayerDetail
class ExportLayerDetail(QgsLayoutItem.ExportLayerDetail)

Bases: sip.wrapper

compositionMode
mapLayerId
mapTheme
name
opacity
class Flag

Bases: int

FlagOverridesPaint = 2
FlagProvidesClipPath = 4
class Flags
class Flags(Union[QgsLayoutItem.Flags, QgsLayoutItem.Flag])
class Flags(QgsLayoutItem.Flags)

Bases: sip.wrapper

ItemContainsSubLayers = 3
LowerLeft = 6
LowerMiddle = 7
LowerRight = 8
Middle = 4
MiddleLeft = 3
MiddleRight = 5
MustPlaceInOwnLayer = 2
class ReferencePoint

Bases: int

UndoArrowHeadFillColor = 76
UndoArrowHeadStrokeColor = 77
UndoArrowHeadWidth = 75
UndoArrowStrokeWidth = 74
UndoAtlasMargin = 12
UndoBackgroundColor = 5
class UndoCommand

Bases: int

UndoCustomCommand = 78
UndoGridFramePenColor = 16
UndoIncrementalMove = 1
UndoIncrementalResize = 2
UndoLabelFont = 31
UndoLabelFontColor = 33
UndoLabelMargin = 32
UndoLabelText = 30
UndoLegendBoxSpace = 50
UndoLegendColumnCount = 35
UndoLegendColumnSpace = 51
UndoLegendFontColor = 49
UndoLegendGroupFont = 56
UndoLegendGroupIndent = 44
UndoLegendGroupSpace = 43
UndoLegendIconSymbolSpace = 48
UndoLegendItemFont = 58
UndoLegendLayerFont = 57
UndoLegendLayerSpace = 46
UndoLegendLineSpacing = 52
UndoLegendMaxSymbolSize = 38
UndoLegendMinSymbolSize = 39
UndoLegendRasterStrokeColor = 54
UndoLegendRasterStrokeWidth = 53
UndoLegendSubgroupIndent = 45
UndoLegendSymbolHeight = 37
UndoLegendSymbolSpace = 47
UndoLegendSymbolWidth = 36
UndoLegendText = 34
UndoLegendTitleFont = 55
UndoLegendTitleSpaceBottom = 42
UndoLegendWmsLegendHeight = 41
UndoLegendWmsLegendWidth = 40
UndoMapAnnotationDistance = 19
UndoMapGridAnnotationFontColor = 20
UndoMapGridFrameFill1Color = 17
UndoMapGridFrameFill2Color = 18
UndoMapGridIntervalRange = 23
UndoMapGridLineSymbol = 21
UndoMapGridMarkerSymbol = 22
UndoMapLabelMargin = 24
UndoMapRotation = 13
UndoNodeMove = 11
UndoNone = -1
UndoOpacity = 6
UndoOverviewStyle = 15
UndoPictureFillColor = 26
UndoPictureNorthOffset = 29
UndoPictureRotation = 25
UndoPictureStrokeColor = 27
UndoPictureStrokeWidth = 28
UndoRotation = 8
UndoScaleBarBoxContentSpace = 73
UndoScaleBarFillColor = 67
UndoScaleBarFillColor2 = 68
UndoScaleBarFontColor = 66
UndoScaleBarHeight = 63
UndoScaleBarLabelBarSize = 72
UndoScaleBarLineWidth = 59
UndoScaleBarMapUnitsSegment = 71
UndoScaleBarSegmentSize = 60
UndoScaleBarSegments = 62
UndoScaleBarSegmentsLeft = 61
UndoScaleBarStrokeColor = 69
UndoScaleBarSubdivisions = 64
UndoScaleBarSubdivisionsHeight = 65
UndoScaleBarUnitText = 70
UndoSetId = 7
UndoShapeCornerRadius = 10
UndoShapeStyle = 9
UndoStrokeColor = 3
UndoStrokeWidth = 4
UndoZoomContent = 14
UpperLeft = 0
UpperMiddle = 1
UpperRight = 2
accept(self, visitor: QgsStyleEntityVisitorInterface) bool

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

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

adjustPointForReferencePosition(self, point: QPointF | QPoint, size: QSizeF, reference: QgsLayoutItem.ReferencePoint) QPointF

Adjusts the specified point at which a reference position of the item sits and returns the top left corner of the item, if reference point were placed at the specified position.

Parameters:
Return type:

QPointF

applyDataDefinedSize(self, size: QgsLayoutSize) QgsLayoutSize

Applies any present data defined size overrides to the specified layout size.

Parameters:

size (QgsLayoutSize) –

Return type:

QgsLayoutSize

applyItemSizeConstraint(self, targetSize: QSizeF) QSizeF

Applies any item-specific size constraint handling to a given targetSize in layout units. Subclasses can override this method if they need to apply advanced logic regarding item sizes, which cannot be covered by setFixedSize() or setMinimumSize(). Item size constraints are applied after fixed, minimum and data defined size constraints.

See also

setFixedSize()

See also

setMinimumSize()

Parameters:

targetSize (QSizeF) –

Return type:

QSizeF

attemptMove(self, point: QgsLayoutPoint, useReferencePoint: bool = True, includesFrame: bool = False, page: int = -1)

Attempts to move the item to a specified point.

If useReferencePoint is True, this method will respect the item’s reference point, in that the item will be moved so that its current reference point is placed at the specified target point.

If useReferencePoint is False, the item will be moved so that point falls at the top-left corner of the item.

If includesFrame is True, then the position specified by point represents the point at which to place the outside of the item’s frame.

If page is not left at the default -1 value, then the position specified by point refers to the relative position on the corresponding layout page (where a page of 0 represents the first page).

Note that the final position of the item may not match the specified target position, as data defined item position may override the specified value.

See also

attemptMoveBy()

See also

attemptResize()

See also

referencePoint()

Parameters:
  • point (QgsLayoutPoint) –

  • useReferencePoint (bool = True) –

  • includesFrame (bool = False) –

  • page (int = -1) –

attemptMoveBy(self, deltaX: float, deltaY: float)

Attempts to shift the item’s position by a specified deltaX and deltaY, in layout units.

Note that the final position of the item may not match the specified offsets, as data defined item position and size may override the specified value.

See also

attemptResize()

See also

attemptMove()

See also

referencePoint()

Parameters:
  • deltaX (float) –

  • deltaY (float) –

attemptResize(self, size: QgsLayoutSize, includesFrame: bool = False)

Attempts to resize the item to a specified target size. Note that the final size of the item may not match the specified target size, as items with a fixed or minimum size will place restrictions on the allowed item size. Data defined item size overrides will also override the specified target size.

If includesFrame is True, then the size specified by size includes the item’s frame.

See also

minimumSize()

See also

fixedSize()

See also

attemptMove()

See also

sizeWithUnits()

Parameters:
attemptSetSceneRect(self, rect: QRectF, includesFrame: bool = False)

Attempts to update the item’s position and size to match the passed rect in layout coordinates.

If includesFrame is True, then the position and size specified by rect represents the position and size at for the outside of the item’s frame.

Note that the final position and size of the item may not match the specified target rect, as data defined item position and size may override the specified value.

See also

attemptResize()

See also

attemptMove()

See also

referencePoint()

Parameters:
  • rect (QRectF) –

  • includesFrame (bool = False) –

backgroundColor(self, useDataDefined: bool = True) QColor

Returns the background color for this item. This is only used if hasBackground() returns True.

Parameters:

useDataDefined (bool = True) – If true, then returns the data defined override for the background color

See also

hasBackground()

Return type:

QColor

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

beginCommand(self, commandText: str, command: QgsLayoutItem.UndoCommand = QgsLayoutItem.UndoNone)

Starts new undo command for this item. The commandText should be a capitalized, imperative tense description (e.g. “Add Map Item”). If specified, multiple consecutive commands for this item with the same command will be collapsed into a single undo command in the layout history.

See also

endCommand()

See also

cancelCommand()

Parameters:
  • commandText (str) –

  • command (QgsLayoutItem.UndoCommand = QgsLayoutItem.UndoNone) –

blendMode(self) QPainter.CompositionMode

Returns the item’s composition blending mode.

See also

setBlendMode()

Return type:

QPainter.CompositionMode

cancelCommand(self)

Cancels the current item command and discards it.

See also

beginCommand()

See also

endCommand()

childEvent(self, QChildEvent)
cleanup(self)

Called just before a batch of items are deleted, allowing them to run cleanup tasks.

clipPath(self) QgsGeometry

Returns the clipping path generated by this item, in layout coordinates.

Note

Not all items can function as clipping paths. The FlagProvidesClipPath flag indicates if a particular item can function as a clipping path provider.

New in version 3.16.

Return type:

QgsGeometry

clipPathChanged

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

connectNotify(self, QMetaMethod)
containsAdvancedEffects(self) bool

Returns True if the item contains contents with blend modes or transparency effects which can only be reproduced by rastering the item.

Subclasses should ensure that implemented overrides of this method also check the base class result.

Return type:

bool

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

  • id (int) –

  • parent (QUndoCommand = None) –

Return type:

QgsAbstractLayoutUndoCommand

createExpressionContext(self) QgsExpressionContext
Return type:

QgsExpressionContext

customEvent(self, QEvent)
disconnectNotify(self, QMetaMethod)
displayName(self) str

Gets item display name. This is the item’s id if set, and if not, a user-friendly string identifying item type.

See also

id()

See also

setId()

Return type:

str

dragEnterEvent(self, QGraphicsSceneDragDropEvent)
dragLeaveEvent(self, QGraphicsSceneDragDropEvent)
dragMoveEvent(self, QGraphicsSceneDragDropEvent)
draw(self, context: QgsLayoutItemRenderContext)

Draws the item’s contents using the specified item render context.

Note that the context’s painter has been scaled so that painter units are pixels. Use the QgsRenderContext methods to convert from millimeters or other units to the painter’s units.

Parameters:

context (QgsLayoutItemRenderContext) –

drawBackground(self, context: QgsRenderContext)

Draws the background for the item.

See also

framePath()

Parameters:

context (QgsRenderContext) –

drawDebugRect(self, painter: QPainter)

Draws a debugging rectangle of the item’s current bounds within the specified painter.

Parameters:

painter (QPainter) – destination QPainter

drawFrame(self, context: QgsRenderContext)

Draws the frame around the item.

See also

framePath()

Parameters:

context (QgsRenderContext) –

dropEvent(self, QGraphicsSceneDragDropEvent)
endCommand(self)

Completes the current item command and push it onto the layout’s undo stack.

See also

beginCommand()

See also

cancelCommand()

estimatedFrameBleed(self) float

Returns the estimated amount the item’s frame bleeds outside the item’s actual rectangle. For instance, if the item has a 2mm frame stroke, then 1mm of this frame is drawn outside the item’s rect. In this case the return value will be 1.0.

Returned values are in layout units.

See also

rectWithFrame()

Return type:

float

excludeFromExports(self) bool

Returns whether the item should be excluded from layout exports and prints.

Return type:

bool

exportLayerBehavior(self) QgsLayoutItem.ExportLayerBehavior

Returns the behavior of this item during exporting to layered exports (e.g. SVG).

New in version 3.10.

Return type:

QgsLayoutItem.ExportLayerBehavior

exportLayerDetails(self) QgsLayoutItem.ExportLayerDetail

Returns the details for the specified current export layer.

Only valid between calls to startLayeredExport() and stopLayeredExport()

New in version 3.10.

Return type:

QgsLayoutItem.ExportLayerDetail

finalizeRestoreFromXml(self)

Called after all pending items have been restored from XML. Items can use this method to run steps which must take place after all items have been restored to the layout, such as connecting to signals emitted by other items, which may not have existed in the layout at the time readXml() was called. E.g. a scalebar can use this to connect to its linked map item after restoration from XML.

See also

readXml()

fixedSize(self) QgsLayoutSize

Returns the fixed size of the item, if applicable, or an empty size if item can be freely resized.

See also

setFixedSize()

See also

minimumSize()

Return type:

QgsLayoutSize

focusInEvent(self, QFocusEvent)
focusOutEvent(self, QFocusEvent)
frameChanged

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

frameEnabled(self) bool

Returns True if the item includes a frame.

See also

frameJoinStyle()

Return type:

bool

frameJoinStyle(self) Qt.PenJoinStyle

Returns the join style used for drawing the item’s frame.

See also

frameEnabled()

Return type:

Qt.PenJoinStyle

framePath(self) QPainterPath

Returns the path to use when drawing the item’s frame or background.

See also

drawFrame()

See also

drawBackground()

New in version 3.16.

Return type:

QPainterPath

frameStrokeColor(self) QColor

Returns the frame’s stroke color. This is only used if frameEnabled() returns True.

See also

frameEnabled()

See also

frameJoinStyle()

Return type:

QColor

frameStrokeWidth(self) QgsLayoutMeasurement

Returns the frame’s stroke width. This is only used if frameEnabled() returns True.

See also

frameEnabled()

See also

frameJoinStyle()

Return type:

QgsLayoutMeasurement

hasBackground(self) bool

Returns True if the item has a background.

Return type:

bool

hoverEnterEvent(self, QGraphicsSceneHoverEvent)
hoverLeaveEvent(self, QGraphicsSceneHoverEvent)
hoverMoveEvent(self, QGraphicsSceneHoverEvent)
icon(self) QIcon

Returns the item’s icon.

Return type:

QIcon

id(self) str

Returns the item’s ID name. This is not necessarily unique, and duplicate ID names may exist for a layout.

See also

setId()

See also

uuid()

Return type:

str

inputMethodEvent(self, QInputMethodEvent)
inputMethodQuery(self, Qt.InputMethodQuery) Any
invalidateCache(self)

Forces a deferred update of any cached image the item uses.

isGroupMember(self) bool

Returns True if the item is part of a QgsLayoutItemGroup group.

See also

parentGroup()

See also

setParentGroup()

Return type:

bool

isLocked(self) bool

Returns True if the item is locked, and cannot be interacted with using the mouse.

See also

setLocked()

See also

lockChanged()

Return type:

bool

isSignalConnected(self, QMetaMethod) bool
itemChange(self, QGraphicsItem.GraphicsItemChange, Any) Any
itemFlags(self) QgsLayoutItem.Flags

Returns the item’s flags, which indicate how the item behaves.

New in version 3.4.3.

Return type:

QgsLayoutItem.Flags

itemOpacity(self) float

Returns the item’s opacity. This method should be used instead of QGraphicsItem.opacity() as any data defined overrides will be respected.

Return type:

float

Returns:

opacity as double between 1.0 (opaque) and 0 (transparent).

See also

setItemOpacity()

itemRotation(self) float

Returns the current rotation for the item, in degrees clockwise.

Note that this method will always return the user-set rotation for the item, which may differ from the current item rotation (if data defined rotation settings are present). Use QGraphicsItem.rotation() to obtain the current item rotation.

Return type:

float

keyPressEvent(self, QKeyEvent)
keyReleaseEvent(self, QKeyEvent)
lockChanged

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

minimumSize(self) QgsLayoutSize

Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely resized.

See also

setMinimumSize()

See also

fixedSize()

Return type:

QgsLayoutSize

mouseDoubleClickEvent(self, QGraphicsSceneMouseEvent)
mouseMoveEvent(self, QGraphicsSceneMouseEvent)
mousePressEvent(self, QGraphicsSceneMouseEvent)
mouseReleaseEvent(self, QGraphicsSceneMouseEvent)
moveContent(self, dx: float, dy: float)

Moves the content of the item, by a specified dx and dy in layout units. The default implementation has no effect.

See also

zoomContent()

Parameters:
  • dx (float) –

  • dy (float) –

nextExportPart(self) bool

Moves to the next export part for a multi-layered export item, during a multi-layered export.

New in version 3.10.

Return type:

bool

numberExportLayers(self) int

Returns the number of layers that this item requires for exporting during layered exports (e.g. SVG). Returns 0 if this item is to be placed on the same layer as the previous item, 1 if it should be placed on its own layer, and >1 if it requires multiple export layers.

Items which require multiply layers should check QgsLayoutContext.currentExportLayer() during their rendering to determine which layer should be drawn.

Deprecated since version Use: nextExportPart() and exportLayerBehavior() instead.

Return type:

int

page(self) int

Returns the page the item is currently on, with the first page returning 0.

See also

pagePos()

Return type:

int

pagePos(self) QPointF

Returns the item’s position (in layout units) relative to the top left corner of its current page.

See also

page()

Return type:

QPointF

pagePositionWithUnits(self) QgsLayoutPoint

Returns the item’s position (in item units) relative to the top left corner of its current page.

See also

page()

See also

pagePos()

Return type:

QgsLayoutPoint

paint(self, painter: QPainter, itemStyle: QStyleOptionGraphicsItem, pWidget: QWidget)

Handles preparing a paint surface for the layout item and painting the item’s content. Derived classes must not override this method, but instead implement the pure virtual method QgsLayoutItem.draw.

Parameters:
  • painter (QPainter) –

  • itemStyle (QStyleOptionGraphicsItem) –

  • pWidget (QWidget) –

parentGroup(self) QgsLayoutItemGroup

Returns the item’s parent group, if the item is part of a QgsLayoutItemGroup group.

See also

isGroupMember()

See also

setParentGroup()

Return type:

QgsLayoutItemGroup

positionAtReferencePoint(self, reference: QgsLayoutItem.ReferencePoint) QPointF

Returns the current position (in layout units) of a reference point for the item.

Parameters:

reference (QgsLayoutItem.ReferencePoint) –

Return type:

QPointF

positionWithUnits(self) QgsLayoutPoint

Returns the item’s current position, including units. The position returned is the position of the item’s reference point, which may not necessarily be the top left corner of the item.

See also

attemptMove()

See also

referencePoint()

See also

sizeWithUnits()

Return type:

QgsLayoutPoint

prepareGeometryChange(self)
readObjectPropertiesFromElement(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool

Sets object properties from a DOM element

Parameters:
  • parentElement – is the parent DOM element for the object

  • document – DOM document

  • context – read write context

Returns:

True if read was successful

readPropertiesFromElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool

Sets item state from a DOM element.

Parameters:
  • element (QDomElement) – is the DOM element for the item

  • document (QDomDocument) – DOM document

  • context (QgsReadWriteContext) – read write context

Note that item subclasses should not rely on all other items being present in the layout at the time this method is called. Instead, any connections and links to other items must be made in the finalizeRestoreFromXml() method. E.g. when restoring a scalebar, the connection to the linked map’s signals should be implemented in finalizeRestoreFromXml(), not readPropertiesFromElement().

See also

readXml()

Return type:

bool

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

Sets the item state from a DOM element.

Parameters:
  • itemElement (QDomElement) – is the DOM node corresponding to item (e.g. ‘LayoutItem’ element)

  • document (QDomDocument) – DOM document

  • context (QgsReadWriteContext) – read write context

Note that item subclasses should not rely on all other items being present in the layout at the time this method is called. Instead, any connections and links to other items must be made in the finalizeRestoreFromXml() method. E.g. when restoring a scalebar, the connection to the linked map’s signals should be implemented in finalizeRestoreFromXml(), not readXml().

See also

writeXml()

Return type:

bool

receivers(self, PYQT_SIGNAL) int
rectWithFrame(self) QRectF

Returns the item’s rectangular bounds, including any bleed caused by the item’s frame. The bounds are returned in the item’s coordinate system (see Qt’s QGraphicsItem docs for more details about QGraphicsItem coordinate systems). The results differ from Qt’s rect() function, as rect() makes no allowances for the portion of outlines which are drawn outside of the item.

Return type:

QRectF

redraw(self)

Triggers a redraw (update) of the item.

referencePoint(self) QgsLayoutItem.ReferencePoint

Returns the reference point for positioning of the layout item. This point is also fixed during resizing of the item, and any size changes will be performed so that the position of the reference point within the layout remains unchanged.

Return type:

QgsLayoutItem.ReferencePoint

refresh(self)

Refreshes the item, causing a recalculation of any property overrides and recalculation of its position and size.

refreshBackgroundColor(self, updateItem: bool = True)

Refresh item’s background color, considering data defined colors. If updateItem is set to False, the item will not be automatically updated after the frame color is set and a later call to update() must be made.

Parameters:

updateItem (bool = True) –

refreshBlendMode(self)

Refresh item’s blend mode, considering data defined blend mode.

refreshDataDefinedProperty(self, property: QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.AllProperties)

Refreshes a data defined property for the item by reevaluating the property’s value and redrawing the item with this new value. If property is set to QgsLayoutObject.AllProperties then all data defined properties for the item will be refreshed.

Parameters:

property (QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.AllProperties) –

refreshFrame(self, updateItem: bool = True)

Refresh item’s frame, considering data defined colors and frame size. If updateItem is set to False, the item will not be automatically updated after the frame is set and a later call to update() must be made.

Parameters:

updateItem (bool = True) –

refreshItemPosition(self)

Refreshes an item’s position by rechecking it against any possible overrides such as data defined positioning.

refreshItemRotation(self, origin: QPointF | QPoint = None)

Refreshes an item’s rotation by rechecking it against any possible overrides such as data defined rotation.

The optional origin point specifies the origin (in item coordinates) around which the rotation should be applied.

Parameters:

origin (Union[QPointF) –

refreshItemSize(self)

Refreshes an item’s size by rechecking it against any possible item fixed or minimum sizes.

See also

setFixedSize()

See also

setMinimumSize()

refreshOpacity(self, updateItem: bool = True)

Refresh item’s opacity, considering data defined opacity. If updateItem is set to False the item will not be automatically updated after the opacity is set and a later call to update() must be made.

Parameters:

updateItem (bool = True) –

requiresRasterization(self) bool

Returns True if the item is drawn in such a way that forces the whole layout to be rasterized when exporting to vector formats.

Return type:

bool

rotateItem(self, angle: float, transformOrigin: QPointF | QPoint)

Rotates the item by a specified angle in degrees clockwise around a specified reference point.

See also

itemRotation()

Parameters:
  • angle (float) –

  • transformOrigin (Union[QPointF) –

rotationChanged

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

sceneEvent(self, QEvent) bool
sceneEventFilter(self, QGraphicsItem, QEvent) bool
sender(self) QObject
senderSignalIndex(self) int
setBackgroundColor(self, color: QColor | Qt.GlobalColor | QGradient)

Sets the background color for this item.

Parameters:

color (Union[QColor) –

setBackgroundEnabled(self, drawBackground: bool)

Sets whether this item has a background drawn under it or not.

See also

hasBackground()

Parameters:

drawBackground (bool) –

setBlendMode(self, mode: QPainter.CompositionMode)

Sets the item’s composition blending mode.

See also

blendMode()

Parameters:

mode (QPainter.CompositionMode) –

setExcludeFromExports(self, exclude: bool)

Sets whether the item should be excluded from layout exports and prints.

Parameters:

exclude (bool) –

setFixedSize(self, size: QgsLayoutSize)

Sets a fixed size for the layout item, which prevents it from being freely resized. Set an empty size if item can be freely resized.

See also

fixedSize()

See also

setMinimumSize()

Parameters:

size (QgsLayoutSize) –

setFrameEnabled(self, drawFrame: bool)

Sets whether this item has a frame drawn around it or not.

See also

frameEnabled()

Parameters:

drawFrame (bool) –

setFrameJoinStyle(self, style: Qt.PenJoinStyle)

Sets the join style used when drawing the item’s frame.

See also

frameJoinStyle()

Parameters:

style (Qt.PenJoinStyle) –

setFrameStrokeColor(self, color: QColor | Qt.GlobalColor | QGradient)

Sets the frame stroke color.

Parameters:

color (Union[QColor) –

setFrameStrokeWidth(self, width: QgsLayoutMeasurement)

Sets the frame stroke width.

Parameters:

width (QgsLayoutMeasurement) –

setId(self, id: str)

Set the item’s id name. This is not necessarily unique, and duplicate ID names may exist for a layout.

See also

id()

See also

uuid()

Parameters:

id (str) –

setItemOpacity(self, opacity: float)

Sets the item’s opacity. This method should be used instead of QGraphicsItem.setOpacity() as any data defined overrides will be respected.

Parameters:

opacity (float) – double between 1.0 (opaque) and 0 (transparent).

See also

itemOpacity()

setItemRotation(self, rotation: float, adjustPosition: bool = True)

Sets the layout item’s rotation, in degrees clockwise.

If adjustPosition is True, then this rotation occurs around the center of the item. If adjustPosition is False, rotation occurs around the item origin.

See also

itemRotation()

See also

rotateItem()

Parameters:
  • rotation (float) –

  • adjustPosition (bool = True) –

setLocked(self, locked: bool)

Sets whether the item is locked, preventing mouse interactions with the item.

See also

isLocked()

See also

lockChanged()

Parameters:

locked (bool) –

setMinimumSize(self, size: QgsLayoutSize)

Sets the minimum allowed size for the layout item. Set an empty size if item can be freely resized.

See also

minimumSize()

See also

setFixedSize()

Parameters:

size (QgsLayoutSize) –

setMoveContentPreviewOffset(self, dx: float, dy: float)

Sets temporary offset for the item, by a specified dx and dy in layout units. This is useful for live updates when moving item content in a QgsLayoutView. The default implementation has no effect.

See also

moveContent()

Parameters:
  • dx (float) –

  • dy (float) –

setParentGroup(self, group: QgsLayoutItemGroup)

Sets the item’s parent group.

See also

isGroupMember()

See also

parentGroup()

Parameters:

group (QgsLayoutItemGroup) –

setReferencePoint(self, point: QgsLayoutItem.ReferencePoint)

Sets the reference point for positioning of the layout item. This point is also fixed during resizing of the item, and any size changes will be performed so that the position of the reference point within the layout remains unchanged.

See also

referencePoint()

Parameters:

point (QgsLayoutItem.ReferencePoint) –

setSelected(self, selected: bool)

Sets whether the item should be selected.

Parameters:

selected (bool) –

setVisibility(self, visible: bool)

Sets whether the item is visible.

Note

QGraphicsItem.setVisible should not be called directly on a QgsLayoutItem, as some item types (e.g., groups) need to override the visibility toggle.

Parameters:

visible (bool) –

shouldDrawItem(self) bool

Returns whether the item should be drawn in the current context.

Return type:

bool

sizePositionChanged

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

sizeWithUnits(self) QgsLayoutSize

Returns the item’s current size, including units.

See also

attemptResize()

Return type:

QgsLayoutSize

startLayeredExport(self)

Starts a multi-layer export operation.

See also

nextExportPart()

New in version 3.10.

stopLayeredExport(self)

Stops a multi-layer export operation.

See also

nextExportPart()

New in version 3.10.

timerEvent(self, QTimerEvent)
topLeftToReferencePoint(self, point: QgsLayoutPoint) QgsLayoutPoint

Returns the position for the reference point of the item, if the top-left of the item was placed at the specified point.

Parameters:

point (QgsLayoutPoint) –

Return type:

QgsLayoutPoint

type(self) int

Returns a unique graphics item type identifier.

Plugin based subclasses should return an identifier greater than QgsLayoutItemRegistry.PluginItem.

Return type:

int

updateMicroFocus(self)
uuid(self) str

Returns the item identification string. This is a unique random string set for the item upon creation.

Note

There is no corresponding setter for the uuid - it’s created automatically.

See also

id()

See also

setId()

Return type:

str

wheelEvent(self, QGraphicsSceneWheelEvent)
writeObjectPropertiesToElement(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool

Stores object properties within an XML DOM element.

Parameters:
  • parentElement – is the parent DOM element to store the object’s properties in

  • document – DOM document

  • context – read write context

Returns:

True if write was successful

writePropertiesToElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool

Stores item state within an XML DOM element.

Parameters:
  • element (QDomElement) – is the DOM element to store the item’s properties in

  • document (QDomDocument) – DOM document

  • context (QgsReadWriteContext) – read write context

See also

writeXml()

Return type:

bool

writeXml(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool

Stores the item state in a DOM element.

Parameters:
  • parentElement (QDomElement) – parent DOM element (e.g. ‘Layout’ element)

  • document (QDomDocument) – DOM document

  • context (QgsReadWriteContext) – read write context

See also

readXml()

Return type:

bool

zoomContent(self, factor: float, point: QPointF | QPoint)

Zooms content of item. Does nothing by default.

Parameters:
  • factor (float) – zoom factor, where > 1 results in a zoom in and < 1 results in a zoom out

  • point (Union[QPointF) – item point for zoom center

See also

moveContent()