Class: QgsLayoutItemPicture

class qgis.core.QgsLayoutItemPicture

Bases: QgsLayoutItem

A layout item subclass that displays SVG files or raster format images (jpg, png, …).

New in version 3.0.

QgsLayoutItemPicture(layout: QgsLayout) Constructor for QgsLayoutItemPicture, with the specified parent layout.

Methods

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

param targetSize:

childEvent

connectNotify

contextMenuEvent

create

Returns a new picture item for the specified layout.

customEvent

disconnectNotify

dragEnterEvent

dragLeaveEvent

dragMoveEvent

draw

param 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

evaluatedPath

Returns the current evaluated picture path, which includes the result of data defined path overrides.

finalizeRestoreFromXml

focusInEvent

focusOutEvent

framePath

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

hoverEnterEvent

hoverLeaveEvent

hoverMoveEvent

icon

rtype:

QIcon

inputMethodEvent

inputMethodQuery

isMissingImage

Returns True if the source image is missing and the picture cannot be rendered.

isSignalConnected

itemChange

keyPressEvent

keyReleaseEvent

linkedMap

Returns the linked rotation map, if set.

mode

Returns the current picture mode (image format), FormatUnknown if given picture format is unknown

mouseDoubleClickEvent

mouseMoveEvent

mousePressEvent

mouseReleaseEvent

northMode

Returns the mode used to align the picture to a map's North.

northOffset

Returns the offset added to the picture's rotation from a map's North.

originalMode

Returns the original set picture mode (image format).

pictureAnchor

Returns the picture's current anchor, which controls how it is placed within the picture item's frame.

picturePath

Returns the path of the source image.

pictureRotation

Returns the rotation used for drawing the picture within the item's frame, in degrees clockwise.

positionAtReferencePoint

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

prepareGeometryChange

readObjectPropertiesFromElement

Sets object properties from a DOM element

readPropertiesFromElement

param element:

recalculateSize

Forces a recalculation of the picture's frame size

receivers

refreshBackgroundColor

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

refreshBlendMode

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

refreshDataDefinedProperty

param property:

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.

refreshPicture

Recalculates the source image (if using an expression for picture's source) and reloads and redraws the picture.

resizeMode

Returns the resize mode used for drawing the picture within the layout item's frame.

sceneEvent

sceneEventFilter

sender

senderSignalIndex

setFixedSize

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

setLinkedMap

Sets the map object for rotation.

setMinimumSize

Sets the minimum allowed size for the layout item.

setMode

Sets the current picture mode (image format).

setNorthMode

Sets the mode used to align the picture to a map's North.

setNorthOffset

Sets the offset added to the picture's rotation from a map's North.

setPictureAnchor

Sets the picture's anchor point, which controls how it is placed within the picture item's frame.

setPicturePath

Sets the source path of the image (may be svg or a raster format).

setPictureRotation

Sets the picture rotation within the item bounds, in degrees clockwise.

setResizeMode

Sets the resize mode used for drawing the picture within the item bounds.

setSvgDynamicParameters

Sets the SVG dynamic parameters

setSvgFillColor

Sets the fill color used for parametrized SVG files.

setSvgStrokeColor

Sets the stroke color used for parametrized SVG files.

setSvgStrokeWidth

Sets the stroke width (in layout units) used for parametrized SVG files.

svgDynamicParameters

Returns the SVG dynamic parameters

svgFillColor

Returns the fill color used for parametrized SVG files.

svgStrokeColor

Returns the stroke color used for parametrized SVG files.

svgStrokeWidth

Returns the stroke width (in layout units) used for parametrized SVG files.

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

rtype:

int

updateMicroFocus

wheelEvent

writeObjectPropertiesToElement

Stores object properties within an XML DOM element.

writePropertiesToElement

param element:

Signals

pictureRotationChanged

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

Attributes

Clip

FormatRaster

FormatSVG

FormatUnknown

FrameToImageSize

GridNorth

Stretch

TrueNorth

Zoom

ZoomResizeFrame

Clip = 2
class Format

Bases: int

FormatRaster = 1
FormatSVG = 0
FormatUnknown = 2
FrameToImageSize = 4
GridNorth = 0
class NorthMode

Bases: int

class ResizeMode

Bases: int

Stretch = 1
TrueNorth = 1
Zoom = 0
ZoomResizeFrame = 3
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.

applyDataDefinedSize(self, size: QgsLayoutSize) QgsLayoutSize

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

applyItemSizeConstraint(self, targetSize: QSizeF) QSizeF
Parameters:

targetSize (QSizeF) –

Return type:

QSizeF

childEvent(self, QChildEvent)
connectNotify(self, QMetaMethod)
contextMenuEvent(self, QGraphicsSceneContextMenuEvent)
create(layout: QgsLayout) QgsLayoutItemPicture

Returns a new picture item for the specified layout.

The caller takes responsibility for deleting the returned object.

Parameters:

layout (QgsLayout) –

Return type:

QgsLayoutItemPicture

customEvent(self, QEvent)
disconnectNotify(self, QMetaMethod)
dragEnterEvent(self, QGraphicsSceneDragDropEvent)
dragLeaveEvent(self, QGraphicsSceneDragDropEvent)
dragMoveEvent(self, QGraphicsSceneDragDropEvent)
draw(self, context: QgsLayoutItemRenderContext)
Parameters:

context (QgsLayoutItemRenderContext) –

drawBackground(self, context: QgsRenderContext)

Draws the background for the item.

See also

framePath()

drawDebugRect(self, painter: QPainter)

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

Parameters:

painter – destination QPainter

drawFrame(self, context: QgsRenderContext)

Draws the frame around the item.

See also

framePath()

dropEvent(self, QGraphicsSceneDragDropEvent)
evaluatedPath(self) str

Returns the current evaluated picture path, which includes the result of data defined path overrides.

See also

picturePath()

New in version 3.6.

Return type:

str

finalizeRestoreFromXml(self)
focusInEvent(self, QFocusEvent)
focusOutEvent(self, QFocusEvent)
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.

hoverEnterEvent(self, QGraphicsSceneHoverEvent)
hoverLeaveEvent(self, QGraphicsSceneHoverEvent)
hoverMoveEvent(self, QGraphicsSceneHoverEvent)
icon(self) QIcon
Return type:

QIcon

inputMethodEvent(self, QInputMethodEvent)
inputMethodQuery(self, Qt.InputMethodQuery) Any
isMissingImage(self) bool

Returns True if the source image is missing and the picture cannot be rendered.

New in version 3.6.

Return type:

bool

isSignalConnected(self, QMetaMethod) bool
itemChange(self, QGraphicsItem.GraphicsItemChange, Any) Any
keyPressEvent(self, QKeyEvent)
keyReleaseEvent(self, QKeyEvent)
linkedMap(self) QgsLayoutItemMap

Returns the linked rotation map, if set. An None means map rotation is disabled. If this is set then the picture is rotated by the same amount as the specified map object.

See also

setLinkedMap()

Return type:

QgsLayoutItemMap

mode(self) QgsLayoutItemPicture.Format

Returns the current picture mode (image format), FormatUnknown if given picture format is unknown

See also

setMode()

Return type:

QgsLayoutItemPicture.Format

mouseDoubleClickEvent(self, QGraphicsSceneMouseEvent)
mouseMoveEvent(self, QGraphicsSceneMouseEvent)
mousePressEvent(self, QGraphicsSceneMouseEvent)
mouseReleaseEvent(self, QGraphicsSceneMouseEvent)
northMode(self) QgsLayoutItemPicture.NorthMode

Returns the mode used to align the picture to a map’s North.

See also

setNorthMode()

See also

northOffset()

Return type:

QgsLayoutItemPicture.NorthMode

northOffset(self) float

Returns the offset added to the picture’s rotation from a map’s North.

See also

setNorthOffset()

See also

northMode()

Return type:

float

originalMode(self) QgsLayoutItemPicture.Format

Returns the original set picture mode (image format). It could differ from mode() if given picture format is unknown

See also

setMode()

New in version 3.22.

Return type:

QgsLayoutItemPicture.Format

pictureAnchor(self) QgsLayoutItem.ReferencePoint

Returns the picture’s current anchor, which controls how it is placed within the picture item’s frame.

Return type:

QgsLayoutItem.ReferencePoint

picturePath(self) str

Returns the path of the source image. Data defined picture source may override this value. The path can either be a local path or a remote (http) path.

Return type:

str

Returns:

path for the source image

See also

setPicturePath()

See also

evaluatedPath()

pictureRotation(self) float

Returns the rotation used for drawing the picture within the item’s frame, in degrees clockwise.

See also

linkedMap()

Return type:

float

pictureRotationChanged

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

positionAtReferencePoint(self, reference: QgsLayoutItem.ReferencePoint) QPointF

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

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
Parameters:
Return type:

bool

recalculateSize(self)

Forces a recalculation of the picture’s frame size

receivers(self, PYQT_SIGNAL) int
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.

refreshBlendMode(self)

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

refreshDataDefinedProperty(self, property: QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.AllProperties)
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.

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.

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.

refreshPicture(self, context: QgsExpressionContext = None)

Recalculates the source image (if using an expression for picture’s source) and reloads and redraws the picture.

Parameters:

context (QgsExpressionContext = None) – expression context for evaluating data defined picture sources

resizeMode(self) QgsLayoutItemPicture.ResizeMode

Returns the resize mode used for drawing the picture within the layout item’s frame.

See also

setResizeMode()

Return type:

QgsLayoutItemPicture.ResizeMode

sceneEvent(self, QEvent) bool
sceneEventFilter(self, QGraphicsItem, QEvent) bool
sender(self) QObject
senderSignalIndex(self) int
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()

setLinkedMap(self, map: QgsLayoutItemMap)

Sets the map object for rotation.

If this is set then the picture will be rotated by the same amount as the specified map object. This is useful especially for syncing north arrows with a map item.

See also

linkedMap()

Parameters:

map (QgsLayoutItemMap) –

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

setMode(self, mode: QgsLayoutItemPicture.Format)

Sets the current picture mode (image format).

See also

mode()

New in version 3.14.

Parameters:

mode (QgsLayoutItemPicture.Format) –

setNorthMode(self, mode: QgsLayoutItemPicture.NorthMode)

Sets the mode used to align the picture to a map’s North.

See also

northMode()

See also

setNorthOffset()

Parameters:

mode (QgsLayoutItemPicture.NorthMode) –

setNorthOffset(self, offset: float)

Sets the offset added to the picture’s rotation from a map’s North.

See also

northOffset()

See also

setNorthMode()

Parameters:

offset (float) –

setPictureAnchor(self, anchor: QgsLayoutItem.ReferencePoint)

Sets the picture’s anchor point, which controls how it is placed within the picture item’s frame.

See also

pictureAnchor()

Parameters:

anchor (QgsLayoutItem.ReferencePoint) –

setPicturePath(self, path: str, format: QgsLayoutItemPicture.Format = QgsLayoutItemPicture.FormatUnknown)

Sets the source path of the image (may be svg or a raster format). Data defined picture source may override this value. The path can either be a local path or a remote (http) path.

Ideally, the format argument should specify the image format.

See also

picturePath()

Parameters:
  • path (str) –

  • format (QgsLayoutItemPicture.Format = QgsLayoutItemPicture.FormatUnknown) –

setPictureRotation(self, rotation: float)

Sets the picture rotation within the item bounds, in degrees clockwise. This does not affect the item’s frame, only the way the picture is drawn within the item.

Parameters:

rotation (float) –

setResizeMode(self, mode: QgsLayoutItemPicture.ResizeMode)

Sets the resize mode used for drawing the picture within the item bounds.

Parameters:

mode (QgsLayoutItemPicture.ResizeMode) – ResizeMode to use for image file

See also

resizeMode()

setSvgDynamicParameters(self, parameters: Dict[str, QgsProperty])

Sets the SVG dynamic parameters

New in version 3.20.

Parameters:

parameters (Dict[str) –

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

Sets the fill color used for parametrized SVG files.

Note

This setting only has an effect on parametrized SVG files, and is ignored for non-parametrized SVG files.

See also

svgFillColor()

Parameters:

color (Union[QColor) –

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

Sets the stroke color used for parametrized SVG files.

Parameters:

color (Union[QColor) – stroke color.

Note

This setting only has an effect on parametrized SVG files, and is ignored for non-parametrized SVG files.

See also

svgStrokeColor()

setSvgStrokeWidth(self, width: float)

Sets the stroke width (in layout units) used for parametrized SVG files.

Note

This setting only has an effect on parametrized SVG files, and is ignored for non-parametrized SVG files.

See also

svgStrokeWidth()

Parameters:

width (float) –

svgDynamicParameters(self) Dict[str, QgsProperty]

Returns the SVG dynamic parameters

New in version 3.20.

Return type:

Dict[str, QgsProperty]

svgFillColor(self) QColor

Returns the fill color used for parametrized SVG files.

See also

svgStrokeColor()

Return type:

QColor

svgStrokeColor(self) QColor

Returns the stroke color used for parametrized SVG files.

See also

svgFillColor()

Return type:

QColor

svgStrokeWidth(self) float

Returns the stroke width (in layout units) used for parametrized SVG files.

See also

svgStrokeColor()

Return type:

float

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.

type(self) int
Return type:

int

updateMicroFocus(self)
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
Parameters:
Return type:

bool