Class: QgsLayoutItemPicture

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

Class Hierarchy

Inheritance diagram of qgis.core.QgsLayoutItemPicture

Base classes

QgsLayoutItem

Base class for graphical items within a QgsLayout.

QgsLayoutObject

A base class for objects which belong to a layout.

QObject

QgsExpressionContextGenerator

Abstract interface for generating an expression context.

QGraphicsRectItem

QAbstractGraphicsShapeItem

QGraphicsItem

QgsLayoutUndoObjectInterface

Interface for layout objects which support undo/redo commands.

class qgis.core.QgsLayoutItemPicture[source]

Bases: QgsLayoutItem

__init__(layout: QgsLayout | None)

Constructor for QgsLayoutItemPicture, with the specified parent layout.

Parameters:

layout (Optional[QgsLayout])

Clip = 2
Format

alias of PictureFormat

FrameToImageSize = 4
GridNorth = 0
class NorthMode

Bases: int

class ResizeMode

Bases: int

Stretch = 1
TrueNorth = 1
Zoom = 0
ZoomResizeFrame = 3
static create(layout: QgsLayout | None) QgsLayoutItemPicture | None[source]

Returns a new picture item for the specified layout.

The caller takes responsibility for deleting the returned object.

Parameters:

layout (Optional[QgsLayout])

Return type:

Optional[QgsLayoutItemPicture]

evaluatedPath(self) str[source]

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

See also

picturePath()

Added in version 3.6.

Return type:

str

isMissingImage(self) bool[source]

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

Added in version 3.6.

Return type:

bool

linkedMap(self) QgsLayoutItemMap | None[source]

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:

Optional[QgsLayoutItemMap]

mode(self) Qgis.PictureFormat[source]

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

See also

setMode()

See also

originalMode()

Return type:

Qgis.PictureFormat

northMode(self) QgsLayoutItemPicture.NorthMode[source]

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

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

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

See also

setMode()

See also

mode()

Added in version 3.22.

Return type:

Qgis.PictureFormat

pictureAnchor(self) QgsLayoutItem.ReferencePoint[source]

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

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

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

See also

linkedMap()

Return type:

float

signal pictureRotationChanged[source]

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

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

recalculateSize(self)[source]

Forces a recalculation of the picture’s frame size

refreshPicture(self, context: QgsExpressionContext | None = None)[source]

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

Parameters:

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

resizeMode(self) QgsLayoutItemPicture.ResizeMode[source]

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

See also

setResizeMode()

Return type:

QgsLayoutItemPicture.ResizeMode

setLinkedMap(self, map: QgsLayoutItemMap | None)[source]

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 (Optional[QgsLayoutItemMap])

setMode(self, mode: Qgis.PictureFormat)[source]

Sets the current picture mode (image format).

See also

mode()

Added in version 3.14.

Parameters:

mode (Qgis.PictureFormat)

setNorthMode(self, mode: QgsLayoutItemPicture.NorthMode)[source]

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

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

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 | None, format: Qgis.PictureFormat = Qgis.PictureFormat.Unknown)[source]

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 (Optional[str])

  • format (Qgis.PictureFormat = Qgis.PictureFormat.Unknown)

setPictureRotation(self, rotation: float)[source]

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

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

Sets the SVG dynamic parameters

Added in version 3.20.

Parameters:

parameters (Dict[Optional[str], QgsProperty])

setSvgFillColor(self, color: QColor | Qt.GlobalColor)[source]

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, Qt.GlobalColor])

setSvgStrokeColor(self, color: QColor | Qt.GlobalColor)[source]

Sets the stroke color used for parametrized SVG files.

Parameters:

color (Union[QColor, Qt.GlobalColor]) – 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)[source]

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

Added in version 3.20.

Return type:

Dict[str, QgsProperty]

svgFillColor(self) QColor[source]

Returns the fill color used for parametrized SVG files.

See also

svgStrokeColor()

Return type:

QColor

svgStrokeColor(self) QColor[source]

Returns the stroke color used for parametrized SVG files.

See also

svgFillColor()

Return type:

QColor

svgStrokeWidth(self) float[source]

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

See also

svgStrokeColor()

Return type:

float