Class: QgsAnnotation¶
Abstract base class for annotation items which are drawn over a map.
QgsAnnotation
is an abstract base class for map annotation
items. These annotations can be drawn within a map, and have either a
fixed map position (retrieved using mapPosition()
) or are
placed relative to the map’s frame (retrieved using
relativePosition()
). Annotations with a fixed map position
also have a corresponding QgsCoordinateReferenceSystem
,
which can be determined by calling mapPositionCrs()
.
Derived classes should implement their custom painting routines within a
renderAnnotation()
override.
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: clone()
, readXml()
, renderAnnotation()
, writeXml()
Class Hierarchy¶
Base classes¶
Subclasses¶
An annotation item that embeds HTML content. |
|
An annotation which renders the contents of an SVG file. |
|
An annotation item that displays formatted text from a QTextDocument document. |
|
An annotation item that embeds a designer form showing the feature attribute. |
Abstract Methods
Clones the annotation, returning a new copy of the annotation reflecting the annotation's current state. |
|
Restores the annotation's state from a DOM element. |
|
Renders the annotation's contents to a target /a context at the specified /a size. |
|
Writes the annotation state to a DOM element. |
Methods
Returns the feature associated with the annotation, or an invalid feature if none has been set. |
|
Returns the margins (in millimeters) between the outside of the frame and the annotation content. |
|
Copies common annotation properties to the targe annotation. |
|
Returns the symbol that is used for rendering the annotation frame. |
|
Returns the annotation's frame's offset (in pixels) from the |
|
Returns the annotation's frame's offset (in millimeters) from the |
|
Returns the size (in pixels) of the annotation's frame (the main area in which the annotation's content is drawn). |
|
Returns the size (in millimeters) of the annotation's frame (the main area in which the annotation's content is drawn). |
|
Returns |
|
Returns |
|
Returns the map layer associated with the annotation. |
|
Returns the map position of the annotation, if it is attached to a fixed map position. |
|
Returns the CRS of the map position, or an invalid CRS if the annotation does not have a fixed map position. |
|
Returns the symbol that is drawn at the annotation's map position. |
|
Returns the relative position of the annotation, if it is not attached to a fixed map position. |
|
Renders the annotation to a target render context. |
|
Sets the margins (in millimeters) between the outside of the frame and the annotation content. |
|
Sets the fill symbol used for rendering the annotation frame. |
|
Sets the annotation's frame's offset (in pixels) from the |
|
Sets the annotation's frame's offset (in millimeters) from the |
|
Sets the size (in pixels) of the annotation's frame (the main area in which the annotation's content is drawn). |
|
Sets the size (in millimeters) of the annotation's frame (the main area in which the annotation's content is drawn). |
|
Sets whether the annotation is attached to a fixed map position, or uses a position relative to the current map extent. |
|
Sets the map layer associated with the annotation. |
|
Sets the map position of the annotation, if it is attached to a fixed map position. |
|
Sets the CRS of the map position. |
|
Sets the symbol that is drawn at the annotation's map position. |
|
Sets the relative position of the annotation, if it is not attached to a fixed map position. |
|
Sets whether the annotation is visible and should be rendered. |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsAnnotation. See the FAQ for more details.
Accepts the specified style entity visitor, causing it to visit all style entities associated within the annotation. |
|
Returns the minimum frame size for the annotation. |
|
Sets the feature associated with the annotation. |
Signals
Emitted whenever the annotation's appearance changes |
|
Emitted when the map layer associated with the annotation changes. |
|
Emitted when the annotation's position has changed and items need to be moved to reflect this. |
- class qgis.core.QgsAnnotation[source]¶
Bases:
QObject
- __init__(parent: QObject | None = None)
Constructor for QgsAnnotation.
- Parameters:
parent (Optional[QObject] = None)
- virtual accept(self, visitor: QgsStyleEntityVisitorInterface | None) bool [source]¶
Accepts the specified style entity
visitor
, causing it to visit all style entities associated within the annotation.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
- associatedFeature(self) QgsFeature [source]¶
Returns the feature associated with the annotation, or an invalid feature if none has been set.
See also
- Return type:
- abstract clone(self) QgsAnnotation | None [source]¶
Clones the annotation, returning a new copy of the annotation reflecting the annotation’s current state.
- Return type:
Optional[QgsAnnotation]
- contentsMargin(self) QgsMargins [source]¶
Returns the margins (in millimeters) between the outside of the frame and the annotation content.
See also
- Return type:
- copyCommonProperties(self, target: QgsAnnotation | None)[source]¶
Copies common annotation properties to the
targe
annotation. Can be used withinQgsAnnotation.clone()
implementations to assist with creating copies.- Parameters:
target (Optional[QgsAnnotation])
- fillSymbol(self) QgsFillSymbol | None [source]¶
Returns the symbol that is used for rendering the annotation frame.
See also
- Return type:
Optional[QgsFillSymbol]
- frameOffsetFromReferencePoint(self) QPointF [source]¶
Returns the annotation’s frame’s offset (in pixels) from the
mapPosition()
reference point.See also
Deprecated since version 3.40: Use
frameOffsetFromReferencePointMm()
instead.- Return type:
QPointF
- frameOffsetFromReferencePointMm(self) QPointF [source]¶
Returns the annotation’s frame’s offset (in millimeters) from the
mapPosition()
reference point.See also
Added in version 3.4.8.
- Return type:
QPointF
- frameSize(self) QSizeF [source]¶
Returns the size (in pixels) of the annotation’s frame (the main area in which the annotation’s content is drawn).
See also
Deprecated since version 3.40: Use
frameSizeMm()
instead.- Return type:
QSizeF
- frameSizeMm(self) QSizeF [source]¶
Returns the size (in millimeters) of the annotation’s frame (the main area in which the annotation’s content is drawn).
See also
Added in version 3.4.8.
- Return type:
QSizeF
- hasFixedMapPosition(self) bool [source]¶
Returns
True
if the annotation is attached to a fixed map position, orFalse
if the annotation uses a position relative to the current map extent.See also
See also
See also
- Return type:
bool
- isVisible(self) bool [source]¶
Returns
True
if the annotation is visible and should be rendered.See also
- Return type:
bool
- mapLayer(self) QgsMapLayer | None [source]¶
Returns the map layer associated with the annotation. Annotations can be associated with a map layer if their visibility should be synchronized with the layer’s visibility.
See also
- Return type:
Optional[QgsMapLayer]
- mapPosition(self) QgsPointXY [source]¶
Returns the map position of the annotation, if it is attached to a fixed map position.
See also
See also
See also
- Return type:
- mapPositionCrs(self) QgsCoordinateReferenceSystem [source]¶
Returns the CRS of the map position, or an invalid CRS if the annotation does not have a fixed map position.
See also
- Return type:
- markerSymbol(self) QgsMarkerSymbol | None [source]¶
Returns the symbol that is drawn at the annotation’s map position.
See also
- Return type:
Optional[QgsMarkerSymbol]
- virtual minimumFrameSize(self) QSizeF [source]¶
Returns the minimum frame size for the annotation. Subclasses should implement this if they cannot be resized smaller than a certain minimum size.
- Return type:
QSizeF
- signal moved[source]¶
Emitted when the annotation’s position has changed and items need to be moved to reflect this.
- abstract readXml(self, itemElem: QDomElement, context: QgsReadWriteContext)[source]¶
Restores the annotation’s state from a DOM element. Derived classes should call _readXml() within their implementation of this method.
See also
See also
_readXml
- Parameters:
itemElem (QDomElement)
context (QgsReadWriteContext)
- relativePosition(self) QPointF [source]¶
Returns the relative position of the annotation, if it is not attached to a fixed map position. The coordinates in the return point should be between 0 and 1, and represent the relative percentage for the position compared to the map width and height.
See also
- Return type:
QPointF
- render(self, context: QgsRenderContext)[source]¶
Renders the annotation to a target render context.
- Parameters:
context (QgsRenderContext)
- abstract renderAnnotation(self, context: QgsRenderContext, size: QSizeF)[source]¶
Renders the annotation’s contents to a target /a context at the specified /a size. Derived classes should implement their custom annotation drawing logic here.
- Parameters:
context (QgsRenderContext)
size (QSizeF)
- virtual setAssociatedFeature(self, feature: QgsFeature)[source]¶
Sets the feature associated with the annotation.
See also
- Parameters:
feature (QgsFeature)
- setContentsMargin(self, margins: QgsMargins)[source]¶
Sets the margins (in millimeters) between the outside of the frame and the annotation content.
See also
- Parameters:
margins (QgsMargins)
- setFillSymbol(self, symbol: QgsFillSymbol | None)[source]¶
Sets the fill symbol used for rendering the annotation frame. Ownership of the symbol is transferred to the annotation.
See also
- Parameters:
symbol (Optional[QgsFillSymbol])
- setFrameOffsetFromReferencePoint(self, offset: QPointF | QPoint)[source]¶
Sets the annotation’s frame’s offset (in pixels) from the
mapPosition()
reference point.See also
Deprecated since version 3.40: Use
setFrameOffsetFromReferencePointMm()
instead.- Parameters:
offset (Union[QPointF, QPoint])
- setFrameOffsetFromReferencePointMm(self, offset: QPointF | QPoint)[source]¶
Sets the annotation’s frame’s offset (in millimeters) from the
mapPosition()
reference point.See also
Added in version 3.4.8.
- Parameters:
offset (Union[QPointF, QPoint])
- setFrameSize(self, size: QSizeF)[source]¶
Sets the size (in pixels) of the annotation’s frame (the main area in which the annotation’s content is drawn).
See also
Deprecated since version 3.40: Use
setFrameSizeMm()
instead.- Parameters:
size (QSizeF)
- setFrameSizeMm(self, size: QSizeF)[source]¶
Sets the size (in millimeters) of the annotation’s frame (the main area in which the annotation’s content is drawn).
See also
Added in version 3.4.8.
- Parameters:
size (QSizeF)
- setHasFixedMapPosition(self, fixed: bool)[source]¶
Sets whether the annotation is attached to a fixed map position, or uses a position relative to the current map extent.
See also
- Parameters:
fixed (bool)
- setMapLayer(self, layer: QgsMapLayer | None)[source]¶
Sets the map layer associated with the annotation. Annotations can be associated with a map layer if their visibility should be synchronized with the layer’s visibility.
See also
- Parameters:
layer (Optional[QgsMapLayer])
- setMapPosition(self, position: QgsPointXY)[source]¶
Sets the map position of the annotation, if it is attached to a fixed map position.
See also
- Parameters:
position (QgsPointXY)
- setMapPositionCrs(self, crs: QgsCoordinateReferenceSystem)[source]¶
Sets the CRS of the map position.
See also
- Parameters:
- setMarkerSymbol(self, symbol: QgsMarkerSymbol | None)[source]¶
Sets the symbol that is drawn at the annotation’s map position. Ownership of the symbol is transferred to the annotation.
See also
- Parameters:
symbol (Optional[QgsMarkerSymbol])
- setRelativePosition(self, position: QPointF | QPoint)[source]¶
Sets the relative position of the annotation, if it is not attached to a fixed map position. The coordinates in the return point should be between 0 and 1, and represent the relative percentage for the position compared to the map width and height.
See also
- Parameters:
position (Union[QPointF, QPoint])
- setVisible(self, visible: bool)[source]¶
Sets whether the annotation is visible and should be rendered.
See also
- Parameters:
visible (bool)
- abstract writeXml(self, elem: QDomElement, doc: QDomDocument, context: QgsReadWriteContext)[source]¶
Writes the annotation state to a DOM element. Derived classes should call _writeXml() within their implementation of this method.
See also
See also
_writeXml
- Parameters:
elem (QDomElement)
doc (QDomDocument)
context (QgsReadWriteContext)