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

List of all members, including inherited members

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.

Constructor

__init__

Abstract Methods

renderInBounds

Renders the item to the specified render context.

Methods

appliedRotation

Returns the effective on-screen rotation of the item, in degrees clockwise.

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.

rotation

Returns the rotation of the item, in degrees clockwise.

rotationMode

Returns the method used to render the item with respect to the rotation of the map.

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.

setRotation

Sets the rotation of the item, in degrees clockwise.

setRotationMode

Sets the mode used to render the item with respect to the rotation of the map.

class qgis.core.QgsAnnotationRectItem[source]

Bases: QgsAnnotationItem

__init__(bounds: QgsRectangle)

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

Parameters:

bounds (QgsRectangle)

appliedRotation(self, mapRotation: float) float[source]

Returns the effective on-screen rotation of the item, in degrees clockwise.

This is the item’s own rotation(), to which mapRotation (the current map rotation, in degrees clockwise) is added when the item’s rotationMode() is Qgis.SymbolRotationMode.RespectMapRotation and its placement mode is not Qgis.AnnotationPlacementMode.RelativeToMapFrame.

See also

rotation()

See also

rotationMode()

Added in version 4.4.

Parameters:

mapRotation (float)

Return type:

float

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:
rotation(self) float[source]

Returns the rotation of the item, in degrees clockwise.

See also

setRotation()

Added in version 4.4.

Return type:

float

rotationMode(self) Qgis.SymbolRotationMode[source]

Returns the method used to render the item with respect to the rotation of the map.

Added in version 4.4.

Return type:

Qgis.SymbolRotationMode

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)

setRotation(self, rotation: float)[source]

Sets the rotation of the item, in degrees clockwise.

See also

rotation()

Added in version 4.4.

Parameters:

rotation (float)

setRotationMode(self, mode: Qgis.SymbolRotationMode)[source]

Sets the mode used to render the item with respect to the rotation of the map.

See also

rotationMode()

Added in version 4.4.

Parameters:

mode (Qgis.SymbolRotationMode)