Class: QgsAnnotationRectItem

Abstract base class for annotation items which render annotations in a rectangular shape.

Subclasses should implement the pure virtual render() method which takes a painter bounds argument.

Added in version 3.40.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: QgsAnnotationItem.clone(), QgsAnnotationItem.readXml(), renderInBounds(), QgsAnnotationItem.type(), QgsAnnotationItem.writeXml()

Class Hierarchy

Inheritance diagram of qgis.core.QgsAnnotationRectItem

Base classes

QgsAnnotationItem

Abstract base class for annotation items which are drawn with QgsAnnotationLayers.

Subclasses

QgsAnnotationPictureItem

An annotation item which renders a picture.

QgsAnnotationRectangleTextItem

An annotation item which renders paragraphs of text within a rectangle.

Abstract Methods

renderInBounds

Renders the item to the specified render context.

Methods

backgroundEnabled

Returns True if the item's background should be rendered.

backgroundSymbol

Returns the symbol used to render the item's background.

bounds

Returns the bounds of the item.

fixedSize

Returns the fixed size to use for the item, when the placementMode() is Qgis.AnnotationPlacementMode.FixedSize.

fixedSizeUnit

Returns the units to use for fixed item sizes, when the placementMode() is Qgis.AnnotationPlacementMode.FixedSize.

frameEnabled

Returns True if the item's frame should be rendered.

frameSymbol

Returns the symbol used to render the item's frame.

placementMode

Returns the placement mode for the item.

setBackgroundEnabled

Sets whether the item's background should be rendered.

setBackgroundSymbol

Sets the symbol used to render the item's background.

setBounds

Sets the bounds of the item.

setFixedSize

Sets the fixed size to use for the item, when the placementMode() is Qgis.AnnotationPlacementMode.FixedSize.

setFixedSizeUnit

Sets the unit to use for fixed item sizes, when the placementMode() is Qgis.AnnotationPlacementMode.FixedSize.

setFrameEnabled

Sets whether the item's frame should be rendered.

setFrameSymbol

Sets the symbol used to render the item's frame.

setPlacementMode

Sets the placement mode for the item.

class qgis.core.QgsAnnotationRectItem[source]

Bases: QgsAnnotationItem

__init__(bounds: QgsRectangle)

Constructor for QgsAnnotationRectItem, rendering the annotation within the specified bounds geometry.

Parameters:

bounds (QgsRectangle)

backgroundEnabled(self) bool[source]

Returns True if the item’s background should be rendered.

Return type:

bool

backgroundSymbol(self) QgsFillSymbol | None[source]

Returns the symbol used to render the item’s background.

Return type:

Optional[QgsFillSymbol]

bounds(self) QgsRectangle[source]

Returns the bounds of the item.

The coordinate reference system for the item will be the parent layer’s QgsAnnotationLayer.crs().

When the placementMode() is Qgis.AnnotationPlacementMode.FixedSize then the item will be placed at the center of the bounds.

See also

setBounds()

Return type:

QgsRectangle

fixedSize(self) QSizeF[source]

Returns the fixed size to use for the item, when the placementMode() is Qgis.AnnotationPlacementMode.FixedSize.

Units are retrieved via fixedSizeUnit()

See also

setFixedSize()

See also

fixedSizeUnit()

Return type:

QSizeF

fixedSizeUnit(self) Qgis.RenderUnit[source]

Returns the units to use for fixed item sizes, when the placementMode() is Qgis.AnnotationPlacementMode.FixedSize.

See also

fixedSize()

Return type:

Qgis.RenderUnit

frameEnabled(self) bool[source]

Returns True if the item’s frame should be rendered.

See also

frameSymbol()

Return type:

bool

frameSymbol(self) QgsFillSymbol | None[source]

Returns the symbol used to render the item’s frame.

See also

frameEnabled()

See also

setFrameSymbol()

Return type:

Optional[QgsFillSymbol]

placementMode(self) Qgis.AnnotationPlacementMode[source]

Returns the placement mode for the item.

Return type:

Qgis.AnnotationPlacementMode

abstract renderInBounds(self, context: QgsRenderContext, painterRect: QRectF, feedback: QgsFeedback | None)[source]

Renders the item to the specified render context.

The painterRect argument specifies the bounds in painter units where the rectangular item should be rendered within.

The feedback argument can be used to detect render cancellations during expensive render operations.

Parameters:
setBackgroundEnabled(self, enabled: bool)[source]

Sets whether the item’s background should be rendered.

Parameters:

enabled (bool)

setBackgroundSymbol(self, symbol: QgsFillSymbol | None)[source]

Sets the symbol used to render the item’s background.

The item takes ownership of the symbol.

Parameters:

symbol (Optional[QgsFillSymbol])

setBounds(self, bounds: QgsRectangle)[source]

Sets the bounds of the item.

The coordinate reference system for the bounds will be the parent layer’s QgsAnnotationLayer.crs().

When the placementMode() is Qgis.AnnotationPlacementMode.FixedSize then the item will be placed at the center of the bounds.

See also

bounds()

Parameters:

bounds (QgsRectangle)

setFixedSize(self, size: QSizeF)[source]

Sets the fixed size to use for the item, when the placementMode() is Qgis.AnnotationPlacementMode.FixedSize.

Units are set via setFixedSizeUnit()

See also

fixedSize()

Parameters:

size (QSizeF)

setFixedSizeUnit(self, unit: Qgis.RenderUnit)[source]

Sets the unit to use for fixed item sizes, when the placementMode() is Qgis.AnnotationPlacementMode.FixedSize.

See also

fixedSizeUnit()

See also

setFixedSize()

Parameters:

unit (Qgis.RenderUnit)

setFrameEnabled(self, enabled: bool)[source]

Sets whether the item’s frame should be rendered.

See also

frameEnabled()

See also

setFrameSymbol()

Parameters:

enabled (bool)

setFrameSymbol(self, symbol: QgsFillSymbol | None)[source]

Sets the symbol used to render the item’s frame.

The item takes ownership of the symbol.

See also

frameSymbol()

Parameters:

symbol (Optional[QgsFillSymbol])

setPlacementMode(self, mode: Qgis.AnnotationPlacementMode)[source]

Sets the placement mode for the item.

See also

placementMode()

Parameters:

mode (Qgis.AnnotationPlacementMode)