Class: QgsLayoutItem¶
Base class for graphical items within a QgsLayout
.
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: draw()
Class Hierarchy¶
Base classes¶
A base class for objects which belong to a layout. |
|
Abstract interface for generating an expression context. |
|
Interface for layout objects which support undo/redo commands. |
Subclasses¶
Base class for frame items, which form a layout multiframe item. |
|
A layout item subclass for elevation profile plots. |
|
A container for grouping several |
|
A layout item subclass for text labels. |
|
A layout item subclass for map legends. |
|
Layout graphical items for displaying a map. |
|
A layout item for showing marker symbols. |
|
Item representing the paper in a layout. |
|
A layout item subclass that displays SVG files or raster format images (jpg, png, …). |
|
An abstract layout item that provides generic methods for node based shapes such as polygon or polylines. |
|
A layout item subclass for scale bars. |
|
Layout item for basic filled shapes (e.g. rectangles, ellipses). |
|
Implements support of 3D map views in print layouts. |
Abstract Methods
Draws the item's contents using the specified item render context. |
Methods
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. |
|
Applies any present data defined size overrides to the specified layout size. |
|
Attempts to shift the item's position by a specified deltaX and deltaY, in layout units. |
|
Attempts to update the item's position and size to match the passed rect in layout coordinates. |
|
Returns the background color for this item. |
|
Starts new undo command for this item. |
|
Returns the item's composition blending mode. |
|
Cancels the current item command and discards it. |
|
Draws a "refreshing" overlay icon on the item. |
|
Completes the current item command and push it onto the layout's undo stack. |
|
Returns whether the item should be excluded from layout exports and prints. |
|
Returns |
|
Returns the join style used for drawing the item's frame. |
|
Returns the frame's stroke color. |
|
Returns the frame's stroke width. |
|
Returns |
|
Returns the item's ID name. |
|
Returns |
|
Returns |
|
Returns the item's opacity. |
|
Returns the current rotation for the item, in degrees clockwise. |
|
Returns the page the item is currently on, with the first page returning 0. |
|
Returns the item's position (in layout units) relative to the top left corner of its current page. |
|
Returns the item's position (in item units) relative to the top left corner of its current page. |
|
Returns the item's parent group, if the item is part of a |
|
Returns the current position (in layout units) of a reference point for the item. |
|
Returns the item's current position, including units. |
|
Sets the item state from a DOM element. |
|
Returns the reference point for positioning of the layout item. |
|
Refresh item's background color, considering data defined colors. |
|
Refresh item's blend mode, considering data defined blend mode. |
|
Refresh item's frame, considering data defined colors and frame size. |
|
Refreshes an item's position by rechecking it against any possible overrides such as data defined positioning. |
|
Refreshes an item's rotation by rechecking it against any possible overrides such as data defined rotation. |
|
Refreshes an item's size by rechecking it against any possible item fixed or minimum sizes. |
|
Refresh item's opacity, considering data defined opacity. |
|
Sets the background color for this item. |
|
Sets whether this item has a background drawn under it or not. |
|
Sets the item's composition blending mode. |
|
Sets whether the item should be excluded from layout exports and prints. |
|
Sets the join style used when drawing the item's frame. |
|
Sets the frame stroke color. |
|
Sets the item's opacity. |
|
Sets whether the item is locked, preventing mouse interactions with the item. |
|
Sets the item's parent group. |
|
Sets the reference point for positioning of the layout item. |
|
Returns whether the item should be drawn in the current context. |
|
Returns the item's current size, including units. |
|
Returns the position for the reference point of the item, if the top-left of the item was placed at the specified point. |
|
Stores the item state in a DOM element. |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsLayoutItem. See the FAQ for more details.
Accepts the specified style entity visitor, causing it to visit all style entities associated with the layout item. |
|
Applies any item-specific size constraint handling to a given targetSize in layout units. |
|
Attempts to move the item to a specified point. |
|
Attempts to resize the item to a specified target size. |
|
Called just before a batch of items are deleted, allowing them to run cleanup tasks. |
|
Returns the clipping path generated by this item, in layout coordinates. |
|
Returns |
|
Gets item display name. |
|
Draws the background for the item. |
|
Draws a debugging rectangle of the item's current bounds within the specified painter. |
|
Draws the frame around the item. |
|
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle. |
|
Returns the behavior of this item during exporting to layered exports (e.g. SVG or geospatial PDF). |
|
Returns the details for the specified current export layer. |
|
Called after all pending items have been restored from XML. |
|
Returns the fixed size of the item, if applicable, or an empty size if item can be freely resized. |
|
Returns the path to use when drawing the item's frame or background. |
|
Returns the item's icon. |
|
Forces a deferred update of any cached image the item uses. |
|
Returns |
|
Returns the item's flags, which indicate how the item behaves. |
|
Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely resized. |
|
Moves the content of the item, by a specified dx and dy in layout units. |
|
Moves to the next export part for a multi-layered export item, during a multi-layered export. |
|
Returns the number of layers that this item requires for exporting during layered exports (e.g. SVG). |
|
Handles preparing a paint surface for the layout item and painting the item's content. |
|
Sets item state from a DOM element. |
|
Returns the item's rectangular bounds, including any bleed caused by the item's frame. |
|
Triggers a redraw (update) of the item. |
|
Refreshes the item, causing a recalculation of any property overrides and recalculation of its position and size. |
|
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the item with this new value. |
|
Returns |
|
Rotates the item by a specified angle in degrees clockwise around a specified reference point. |
|
Sets a fixed size for the layout item, which prevents it from being freely resized. |
|
Sets whether this item has a frame drawn around it or not. |
|
Sets the frame stroke width. |
|
Set the item's id name. |
|
Sets the layout item's rotation, in degrees clockwise. |
|
Sets the minimum allowed size for the layout item. |
|
Sets temporary offset for the item, by a specified dx and dy in layout units. |
|
Sets whether the item should be selected. |
|
Sets whether the item is visible. |
|
Starts a multi-layer export operation. |
|
Stops a multi-layer export operation. |
|
Returns a unique graphics item type identifier. |
|
Returns the item identification string. |
|
Stores item state within an XML DOM element. |
|
Zooms content of item. |
Signals
Emitted whenever the number of background tasks an item is executing changes. |
|
Emitted when the item's clipping path has changed. |
|
Emitted if the item's frame style changes. |
|
Emitted if the item's lock status changes. |
|
Emitted on item rotation change. |
|
Emitted when the item's size or position changes. |
Attributes
- class qgis.core.QgsLayoutItem[source]¶
Bases:
QgsLayoutObject
,QGraphicsRectItem
,QgsLayoutUndoObjectInterface
- __init__(layout: QgsLayout | None, manageZValue: bool = True)
Constructor for QgsLayoutItem, with the specified parent
layout
.If
manageZValue
isTrue
, the z-Value of this item will be managed by the layout. Generally this is the desired behavior.- Parameters:
layout (Optional[QgsLayout])
manageZValue (bool = True)
- CanGroupWithAnyOtherItem = 0¶
- CanGroupWithItemsOfSameType = 1¶
- class ExportLayerBehavior¶
Bases:
int
- class ExportLayerDetail¶
Bases:
object
Contains details of a particular export layer relating to a layout item.
Added in version 3.10.
- compositionMode: QPainter.CompositionMode¶
Associated composition mode if this layer is associated with a map layer
Added in version 3.14.
- groupName: str¶
Associated group name, if this layer is associated with an export group.
Added in version 3.40.
- mapLayerId: str¶
Associated map layer ID, or an empty string if this export layer is not associated with a map layer
- mapTheme: str¶
Associated map theme, or an empty string if this export layer does not need to be associated with a map theme
- name: str¶
User-friendly name for the export layer
- class Flag¶
Bases:
int
- FlagDisableSceneCaching = 8¶
- FlagOverridesPaint = 2¶
- FlagProvidesClipPath = 4¶
- class Flags¶
- class Flags(f: QgsLayoutItem.Flags | QgsLayoutItem.Flag)
- class Flags(a0: QgsLayoutItem.Flags)
Bases:
object
- ItemContainsSubLayers = 3¶
- LowerLeft = 6¶
- LowerMiddle = 7¶
- LowerRight = 8¶
- Middle = 4¶
- MiddleLeft = 3¶
- MiddleRight = 5¶
- MustPlaceInOwnLayer = 2¶
- class ReferencePoint¶
Bases:
int
- UndoArrowHeadFillColor = 82¶
- UndoArrowHeadStrokeColor = 83¶
- UndoArrowHeadWidth = 81¶
- UndoArrowStrokeWidth = 80¶
- UndoAtlasMargin = 17¶
- UndoBackgroundColor = 5¶
- class UndoCommand¶
Bases:
int
- UndoCustomCommand = 102¶
- UndoElevationProfileChartBackground = 85¶
- UndoElevationProfileChartBorder = 86¶
- UndoElevationProfileDistanceFont = 90¶
- UndoElevationProfileDistanceFormat = 89¶
- UndoElevationProfileDistanceLabels = 91¶
- UndoElevationProfileDistanceMajorGridlines = 87¶
- UndoElevationProfileDistanceMinorGridlines = 88¶
- UndoElevationProfileElevationFont = 95¶
- UndoElevationProfileElevationFormat = 94¶
- UndoElevationProfileElevationLabels = 96¶
- UndoElevationProfileElevationMajorGridlines = 92¶
- UndoElevationProfileElevationMinorGridlines = 93¶
- UndoElevationProfileMaximumDistance = 98¶
- UndoElevationProfileMaximumElevation = 100¶
- UndoElevationProfileMinimumDistance = 97¶
- UndoElevationProfileMinimumElevation = 99¶
- UndoElevationProfileSubsectionLines = 101¶
- UndoElevationProfileTolerance = 84¶
- UndoExportLayerName = 13¶
- UndoGridFramePenColor = 21¶
- UndoIncrementalMove = 1¶
- UndoIncrementalResize = 2¶
- UndoLabelFont = 36¶
- UndoLabelFontColor = 38¶
- UndoLabelMargin = 37¶
- UndoLabelText = 35¶
- UndoLegendAutoWrapAfter = 64¶
- UndoLegendBoxSpace = 55¶
- UndoLegendColumnCount = 40¶
- UndoLegendColumnSpace = 56¶
- UndoLegendFontColor = 54¶
- UndoLegendGroupFont = 61¶
- UndoLegendGroupIndent = 49¶
- UndoLegendGroupSpace = 48¶
- UndoLegendIconSymbolSpace = 53¶
- UndoLegendItemFont = 63¶
- UndoLegendLayerFont = 62¶
- UndoLegendLayerSpace = 51¶
- UndoLegendLineSpacing = 57¶
- UndoLegendMaxSymbolSize = 43¶
- UndoLegendMinSymbolSize = 44¶
- UndoLegendRasterStrokeColor = 59¶
- UndoLegendRasterStrokeWidth = 58¶
- UndoLegendSubgroupIndent = 50¶
- UndoLegendSymbolHeight = 42¶
- UndoLegendSymbolSpace = 52¶
- UndoLegendSymbolWidth = 41¶
- UndoLegendText = 39¶
- UndoLegendTitleFont = 60¶
- UndoLegendTitleSpaceBottom = 47¶
- UndoLegendWmsLegendHeight = 46¶
- UndoLegendWmsLegendWidth = 45¶
- UndoMapAnnotationDistance = 24¶
- UndoMapGridAnnotationFontColor = 25¶
- UndoMapGridFrameFill1Color = 22¶
- UndoMapGridFrameFill2Color = 23¶
- UndoMapGridIntervalRange = 28¶
- UndoMapGridLineSymbol = 26¶
- UndoMapGridMarkerSymbol = 27¶
- UndoMapLabelMargin = 29¶
- UndoMapRotation = 18¶
- UndoMarginBottom = 9¶
- UndoMarginLeft = 7¶
- UndoMarginRight = 10¶
- UndoMarginTop = 8¶
- UndoNodeMove = 16¶
- UndoNone = -1¶
- UndoOpacity = 6¶
- UndoOverviewStyle = 20¶
- UndoPictureFillColor = 31¶
- UndoPictureNorthOffset = 34¶
- UndoPictureRotation = 30¶
- UndoPictureStrokeColor = 32¶
- UndoPictureStrokeWidth = 33¶
- UndoRotation = 12¶
- UndoScaleBarBoxContentSpace = 79¶
- UndoScaleBarFillColor = 73¶
- UndoScaleBarFillColor2 = 74¶
- UndoScaleBarFontColor = 72¶
- UndoScaleBarHeight = 69¶
- UndoScaleBarLabelBarSize = 78¶
- UndoScaleBarLineWidth = 65¶
- UndoScaleBarMapUnitsSegment = 77¶
- UndoScaleBarSegmentSize = 66¶
- UndoScaleBarSegments = 68¶
- UndoScaleBarSegmentsLeft = 67¶
- UndoScaleBarStrokeColor = 75¶
- UndoScaleBarSubdivisions = 70¶
- UndoScaleBarSubdivisionsHeight = 71¶
- UndoScaleBarUnitText = 76¶
- UndoSetId = 11¶
- UndoShapeCornerRadius = 15¶
- UndoShapeStyle = 14¶
- UndoStrokeColor = 3¶
- UndoStrokeWidth = 4¶
- UndoZoomContent = 19¶
- UpperLeft = 0¶
- UpperMiddle = 1¶
- UpperRight = 2¶
- virtual accept(self, visitor: QgsStyleEntityVisitorInterface | None) bool [source]¶
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, orFalse
if visiting should be canceled.Added in version 3.10.
- Parameters:
visitor (Optional[QgsStyleEntityVisitorInterface])
- Return type:
bool
- adjustPointForReferencePosition(self, point: QPointF | QPoint, size: QSizeF, reference: QgsLayoutItem.ReferencePoint) QPointF [source]¶
Adjusts the specified
point
at which areference
position of the item sits and returns the top left corner of the item, if reference point were placed at the specified position.- Parameters:
point (Union[QPointF, QPoint])
size (QSizeF)
reference (QgsLayoutItem.ReferencePoint)
- Return type:
QPointF
- applyDataDefinedSize(self, size: QgsLayoutSize) QgsLayoutSize [source]¶
Applies any present data defined size overrides to the specified layout
size
.- Parameters:
size (QgsLayoutSize)
- Return type:
- virtual applyItemSizeConstraint(self, targetSize: QSizeF) QSizeF [source]¶
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 bysetFixedSize()
orsetMinimumSize()
. Item size constraints are applied after fixed, minimum and data defined size constraints.See also
See also
- Parameters:
targetSize (QSizeF)
- Return type:
QSizeF
- virtual attemptMove(self, point: QgsLayoutPoint, useReferencePoint: bool = True, includesFrame: bool = False, page: int = -1)[source]¶
Attempts to move the item to a specified
point
.If
useReferencePoint
isTrue
, 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
isFalse
, the item will be moved so thatpoint
falls at the top-left corner of the item.If
includesFrame
isTrue
, then the position specified bypoint
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 bypoint
refers to the relative position on the corresponding layoutpage
(where apage
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
See also
See also
See also
- Parameters:
point (QgsLayoutPoint)
useReferencePoint (bool = True)
includesFrame (bool = False)
page (int = -1)
- attemptMoveBy(self, deltaX: float, deltaY: float)[source]¶
Attempts to shift the item’s position by a specified
deltaX
anddeltaY
, 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
See also
See also
See also
- Parameters:
deltaX (float)
deltaY (float)
- virtual attemptResize(self, size: QgsLayoutSize, includesFrame: bool = False)[source]¶
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
isTrue
, then the size specified bysize
includes the item’s frame.See also
See also
See also
See also
- Parameters:
size (QgsLayoutSize)
includesFrame (bool = False)
- attemptSetSceneRect(self, rect: QRectF, includesFrame: bool = False)[source]¶
Attempts to update the item’s position and size to match the passed
rect
in layout coordinates.If
includesFrame
isTrue
, then the position and size specified byrect
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
See also
See also
See also
- Parameters:
rect (QRectF)
includesFrame (bool = False)
- backgroundColor(self, useDataDefined: bool = True) QColor [source]¶
Returns the background color for this item. This is only used if
hasBackground()
returnsTrue
.- Parameters:
useDataDefined (bool = True) – If true, then returns the data defined override for the background color
See also
See also
- Return type:
QColor
- signal backgroundTaskCountChanged(count: int)[source]¶
Emitted whenever the number of background tasks an item is executing changes.
Added in version 3.10.
- Parameters:
count (int)
- beginCommand(self, commandText: str | None, command: QgsLayoutItem.UndoCommand = QgsLayoutItem.UndoNone)[source]¶
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 samecommand
will be collapsed into a single undo command in the layout history.See also
See also
- Parameters:
commandText (Optional[str])
command (QgsLayoutItem.UndoCommand = QgsLayoutItem.UndoNone)
- blendMode(self) QPainter.CompositionMode [source]¶
Returns the item’s composition blending mode.
See also
- Return type:
QPainter.CompositionMode
- virtual cleanup(self)[source]¶
Called just before a batch of items are deleted, allowing them to run cleanup tasks.
- virtual clipPath(self) QgsGeometry [source]¶
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.
Added in version 3.16.
- Return type:
- signal clipPathChanged[source]¶
Emitted when the item’s clipping path has changed.
See also
Added in version 3.16.
- virtual containsAdvancedEffects(self) bool [source]¶
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.
See also
- Return type:
bool
- virtual displayName(self) str [source]¶
Gets item display name. This is the item’s id if set, and if not, a user-friendly string identifying item type.
See also
See also
- Return type:
str
- abstract draw(self, context: QgsLayoutItemRenderContext)[source]¶
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)
- virtual drawBackground(self, context: QgsRenderContext)[source]¶
Draws the background for the item.
See also
- Parameters:
context (QgsRenderContext)
- virtual drawDebugRect(self, painter: QPainter | None)[source]¶
Draws a debugging rectangle of the item’s current bounds within the specified painter.
- Parameters:
painter (Optional[QPainter]) – destination QPainter
- virtual drawFrame(self, context: QgsRenderContext)[source]¶
Draws the frame around the item.
See also
- Parameters:
context (QgsRenderContext)
- drawRefreshingOverlay(self, painter: QPainter | None, itemStyle: QStyleOptionGraphicsItem | None)[source]¶
Draws a “refreshing” overlay icon on the item.
Added in version 3.32.
- Parameters:
painter (Optional[QPainter])
itemStyle (Optional[QStyleOptionGraphicsItem])
- endCommand(self)[source]¶
Completes the current item command and push it onto the layout’s undo stack.
See also
See also
- virtual estimatedFrameBleed(self) float [source]¶
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
- Return type:
float
- excludeFromExports(self) bool [source]¶
Returns whether the item should be excluded from layout exports and prints.
See also
- Return type:
bool
- virtual exportLayerBehavior(self) QgsLayoutItem.ExportLayerBehavior [source]¶
Returns the behavior of this item during exporting to layered exports (e.g. SVG or geospatial PDF).
See also
See also
Added in version 3.10.
- Return type:
- virtual exportLayerDetails(self) QgsLayoutItem.ExportLayerDetail [source]¶
Returns the details for the specified current export layer.
Only valid between calls to
startLayeredExport()
andstopLayeredExport()
Added in version 3.10.
- Return type:
- virtual finalizeRestoreFromXml(self)[source]¶
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
- virtual fixedSize(self) QgsLayoutSize [source]¶
Returns the fixed size of the item, if applicable, or an empty size if item can be freely resized.
See also
See also
- Return type:
- frameEnabled(self) bool [source]¶
Returns
True
if the item includes a frame.See also
See also
See also
See also
- Return type:
bool
- frameJoinStyle(self) Qt.PenJoinStyle [source]¶
Returns the join style used for drawing the item’s frame.
See also
See also
See also
See also
- Return type:
Qt.PenJoinStyle
- virtual framePath(self) QPainterPath [source]¶
Returns the path to use when drawing the item’s frame or background.
See also
See also
Added in version 3.16.
- Return type:
QPainterPath
- frameStrokeColor(self) QColor [source]¶
Returns the frame’s stroke color. This is only used if
frameEnabled()
returnsTrue
.See also
See also
See also
See also
- Return type:
QColor
- frameStrokeWidth(self) QgsLayoutMeasurement [source]¶
Returns the frame’s stroke width. This is only used if
frameEnabled()
returnsTrue
.See also
See also
See also
See also
- Return type:
- hasBackground(self) bool [source]¶
Returns
True
if the item has a background.See also
See also
- Return type:
bool
- id(self) str [source]¶
Returns the item’s ID name. This is not necessarily unique, and duplicate ID names may exist for a layout.
See also
See also
- Return type:
str
- isGroupMember(self) bool [source]¶
Returns
True
if the item is part of aQgsLayoutItemGroup
group.See also
See also
- Return type:
bool
- isLocked(self) bool [source]¶
Returns
True
if the item is locked, and cannot be interacted with using the mouse.See also
See also
- Return type:
bool
- virtual isRefreshing(self) bool [source]¶
Returns
True
if the item is currently refreshing content in the background.Added in version 3.32.
- Return type:
bool
- virtual itemFlags(self) QgsLayoutItem.Flags [source]¶
Returns the item’s flags, which indicate how the item behaves.
Added in version 3.4.3.
- Return type:
- itemOpacity(self) float [source]¶
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
- itemRotation(self) float [source]¶
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.
See also
- Return type:
float
- virtual minimumSize(self) QgsLayoutSize [source]¶
Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely resized.
See also
See also
- Return type:
- virtual moveContent(self, dx: float, dy: float)[source]¶
Moves the content of the item, by a specified
dx
anddy
in layout units. The default implementation has no effect.See also
See also
- Parameters:
dx (float)
dy (float)
- virtual nextExportPart(self) bool [source]¶
Moves to the next export part for a multi-layered export item, during a multi-layered export.
See also
See also
Added in version 3.10.
- Return type:
bool
- virtual numberExportLayers(self) int [source]¶
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.See also
See also
Deprecated since version 3.40: Use
nextExportPart()
andexportLayerBehavior()
instead.- Return type:
int
- page(self) int [source]¶
Returns the page the item is currently on, with the first page returning 0.
See also
- Return type:
int
- pagePos(self) QPointF [source]¶
Returns the item’s position (in layout units) relative to the top left corner of its current page.
See also
See also
- Return type:
QPointF
- pagePositionWithUnits(self) QgsLayoutPoint [source]¶
Returns the item’s position (in item units) relative to the top left corner of its current page.
See also
See also
- Return type:
- virtual paint(self, painter: QPainter | None, itemStyle: QStyleOptionGraphicsItem | None, pWidget: QWidget | None)[source]¶
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 (Optional[QPainter])
itemStyle (Optional[QStyleOptionGraphicsItem])
pWidget (Optional[QWidget])
- parentGroup(self) QgsLayoutItemGroup | None [source]¶
Returns the item’s parent group, if the item is part of a
QgsLayoutItemGroup
group.See also
See also
- Return type:
Optional[QgsLayoutItemGroup]
- positionAtReferencePoint(self, reference: QgsLayoutItem.ReferencePoint) QPointF [source]¶
Returns the current position (in layout units) of a
reference
point for the item.- Parameters:
reference (QgsLayoutItem.ReferencePoint)
- Return type:
QPointF
- positionWithUnits(self) QgsLayoutPoint [source]¶
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
See also
See also
- Return type:
- virtual readPropertiesFromElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool [source]¶
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 infinalizeRestoreFromXml()
, notreadPropertiesFromElement()
.See also
See also
- Return type:
bool
- readXml(self, itemElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool [source]¶
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 infinalizeRestoreFromXml()
, notreadXml()
.See also
See also
- Return type:
bool
- virtual rectWithFrame(self) QRectF [source]¶
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, asrect()
makes no allowances for the portion of outlines which are drawn outside of the item.See also
- Return type:
QRectF
- referencePoint(self) QgsLayoutItem.ReferencePoint [source]¶
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.
See also
- Return type:
- virtual refresh(self)[source]¶
Refreshes the item, causing a recalculation of any property overrides and recalculation of its position and size.
- refreshBackgroundColor(self, updateItem: bool = True)[source]¶
Refresh item’s background color, considering data defined colors. If
updateItem
is set toFalse
, the item will not be automatically updated after the frame color is set and a later call toupdate()
must be made.- Parameters:
updateItem (bool = True)
- virtual refreshDataDefinedProperty(self, property: QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.DataDefinedProperty.AllProperties)[source]¶
Refreshes a data defined
property
for the item by reevaluating the property’s value and redrawing the item with this new value. Ifproperty
is set toQgsLayoutObject
.AllProperties then all data defined properties for the item will be refreshed.- Parameters:
property (QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.DataDefinedProperty.AllProperties)
- refreshFrame(self, updateItem: bool = True)[source]¶
Refresh item’s frame, considering data defined colors and frame size. If
updateItem
is set toFalse
, the item will not be automatically updated after the frame is set and a later call toupdate()
must be made.- Parameters:
updateItem (bool = True)
- refreshItemPosition(self)[source]¶
Refreshes an item’s position by rechecking it against any possible overrides such as data defined positioning.
See also
- refreshItemRotation(self, origin: QPointF | QPoint | None = None)[source]¶
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.See also
See also
- Parameters:
origin (Optional[Union[QPointF, QPoint]] = None)
- refreshItemSize(self)[source]¶
Refreshes an item’s size by rechecking it against any possible item fixed or minimum sizes.
See also
See also
See also
- refreshOpacity(self, updateItem: bool = True)[source]¶
Refresh item’s opacity, considering data defined opacity. If
updateItem
is set toFalse
the item will not be automatically updated after the opacity is set and a later call toupdate()
must be made.- Parameters:
updateItem (bool = True)
- virtual requiresRasterization(self) bool [source]¶
Returns
True
if the item is drawn in such a way that forces the whole layout to be rasterized when exporting to vector formats.See also
- Return type:
bool
- virtual rotateItem(self, angle: float, transformOrigin: QPointF | QPoint)[source]¶
Rotates the item by a specified
angle
in degrees clockwise around a specified reference point.See also
See also
- Parameters:
angle (float)
transformOrigin (Union[QPointF, QPoint])
- signal rotationChanged(newRotation: float)[source]¶
Emitted on item rotation change.
- Parameters:
newRotation (float)
- setBackgroundColor(self, color: QColor | Qt.GlobalColor)[source]¶
Sets the background
color
for this item.See also
See also
- Parameters:
color (Union[QColor, Qt.GlobalColor])
- setBackgroundEnabled(self, drawBackground: bool)[source]¶
Sets whether this item has a background drawn under it or not.
See also
See also
- Parameters:
drawBackground (bool)
- setBlendMode(self, mode: QPainter.CompositionMode)[source]¶
Sets the item’s composition blending
mode
.See also
- Parameters:
mode (QPainter.CompositionMode)
- setExcludeFromExports(self, exclude: bool)[source]¶
Sets whether the item should be excluded from layout exports and prints.
See also
- Parameters:
exclude (bool)
- virtual setFixedSize(self, size: QgsLayoutSize)[source]¶
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
See also
- Parameters:
size (QgsLayoutSize)
- virtual setFrameEnabled(self, drawFrame: bool)[source]¶
Sets whether this item has a frame drawn around it or not.
See also
See also
See also
See also
- Parameters:
drawFrame (bool)
- setFrameJoinStyle(self, style: Qt.PenJoinStyle)[source]¶
Sets the join
style
used when drawing the item’s frame.See also
See also
See also
See also
- Parameters:
style (Qt.PenJoinStyle)
- setFrameStrokeColor(self, color: QColor | Qt.GlobalColor)[source]¶
Sets the frame stroke
color
.See also
See also
See also
See also
- Parameters:
color (Union[QColor, Qt.GlobalColor])
- virtual setFrameStrokeWidth(self, width: QgsLayoutMeasurement)[source]¶
Sets the frame stroke
width
.See also
See also
See also
See also
- Parameters:
width (QgsLayoutMeasurement)
- virtual setId(self, id: str | None)[source]¶
Set the item’s
id
name. This is not necessarily unique, and duplicate ID names may exist for a layout.See also
See also
- Parameters:
id (Optional[str])
- setItemOpacity(self, opacity: float)[source]¶
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
- virtual setItemRotation(self, rotation: float, adjustPosition: bool = True)[source]¶
Sets the layout item’s
rotation
, in degrees clockwise.If
adjustPosition
isTrue
, then this rotation occurs around the center of the item. IfadjustPosition
isFalse
, rotation occurs around the item origin.See also
See also
- Parameters:
rotation (float)
adjustPosition (bool = True)
- setLocked(self, locked: bool)[source]¶
Sets whether the item is
locked
, preventing mouse interactions with the item.See also
See also
- Parameters:
locked (bool)
- virtual setMinimumSize(self, size: QgsLayoutSize)[source]¶
Sets the minimum allowed
size
for the layout item. Set an empty size if item can be freely resized.See also
See also
- Parameters:
size (QgsLayoutSize)
- virtual setMoveContentPreviewOffset(self, dx: float, dy: float)[source]¶
Sets temporary offset for the item, by a specified
dx
anddy
in layout units. This is useful for live updates when moving item content in aQgsLayoutView
. The default implementation has no effect.See also
- Parameters:
dx (float)
dy (float)
- setParentGroup(self, group: QgsLayoutItemGroup | None)[source]¶
Sets the item’s parent
group
.See also
See also
- Parameters:
group (Optional[QgsLayoutItemGroup])
- setReferencePoint(self, point: QgsLayoutItem.ReferencePoint)[source]¶
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
- Parameters:
point (QgsLayoutItem.ReferencePoint)
- virtual setSelected(self, selected: bool)[source]¶
Sets whether the item should be selected.
- Parameters:
selected (bool)
- virtual setVisibility(self, visible: bool)[source]¶
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 [source]¶
Returns whether the item should be drawn in the current context.
- Return type:
bool
- sizeWithUnits(self) QgsLayoutSize [source]¶
Returns the item’s current size, including units.
See also
See also
- Return type:
- virtual startLayeredExport(self)[source]¶
Starts a multi-layer export operation.
See also
See also
Added in version 3.10.
- virtual stopLayeredExport(self)[source]¶
Stops a multi-layer export operation.
See also
See also
Added in version 3.10.
- topLeftToReferencePoint(self, point: QgsLayoutPoint) QgsLayoutPoint [source]¶
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:
- virtual type(self) int [source]¶
Returns a unique graphics item type identifier.
Plugin based subclasses should return an identifier greater than
QgsLayoutItemRegistry
.PluginItem.- Return type:
int
- virtual uuid(self) str [source]¶
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
See also
- Return type:
str
- virtual writePropertiesToElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool [source]¶
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
See also
- Return type:
bool
- writeXml(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool [source]¶
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
- Return type:
bool