Class: QgsAnnotation¶
- class qgis.core.QgsAnnotation¶
Bases:
PyQt5.QtCore.QObject
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 usingmapPosition()
) or are placed relative to the map’s frame (retrieved usingrelativePosition()
). Annotations with a fixed map position also have a correspondingQgsCoordinateReferenceSystem
, which can be determined by callingmapPositionCrs()
.Derived classes should implement their custom painting routines within a
renderAnnotation()
override.New in version 3.0.
QgsAnnotation(parent: QObject = None) Constructor for QgsAnnotation.
Methods
Accepts the specified style entity
visitor
, causing it to visit all style entities associated within the annotation.Returns the feature associated with the annotation, or an invalid feature if none has been set.
Clones the annotation, returning a new copy of the annotation reflecting the annotation's current state.
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
mapPosition()
reference point.Returns the annotation's frame's offset (in millimeters) from the
mapPosition()
reference point.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
True
if the annotation is attached to a fixed map position, orFalse
if the annotation uses a position relative to the current map extent.Returns
True
if the annotation is visible and should be rendered.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 minimum frame size for the annotation.
Restores the annotation's state from a DOM element.
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.
Renders the annotation's contents to a target /a context at the specified /a size.
Sets the feature associated with the annotation.
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
mapPosition()
reference point.Sets the annotation's frame's offset (in millimeters) from the
mapPosition()
reference point.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.
Writes the annotation state to a DOM element.
Signals
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
- accept(self, visitor: QgsStyleEntityVisitorInterface) bool ¶
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.New in version 3.10.
- Parameters:
visitor (QgsStyleEntityVisitorInterface) –
- Return type:
bool
- appearanceChanged¶
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
- associatedFeature(self) QgsFeature ¶
Returns the feature associated with the annotation, or an invalid feature if none has been set.
See also
- Return type:
- childEvent(self, QChildEvent)¶
- clone(self) QgsAnnotation ¶
Clones the annotation, returning a new copy of the annotation reflecting the annotation’s current state.
- Return type:
- connectNotify(self, QMetaMethod)¶
- contentsMargin(self) QgsMargins ¶
Returns the margins (in millimeters) between the outside of the frame and the annotation content.
See also
- Return type:
- copyCommonProperties(self, target: QgsAnnotation)¶
Copies common annotation properties to the
targe
annotation. Can be used withinQgsAnnotation.clone()
implementations to assist with creating copies.- Parameters:
target (QgsAnnotation) –
- customEvent(self, QEvent)¶
- disconnectNotify(self, QMetaMethod)¶
- fillSymbol(self) QgsFillSymbol ¶
Returns the symbol that is used for rendering the annotation frame.
See also
- Return type:
- frameOffsetFromReferencePoint(self) QPointF ¶
Returns the annotation’s frame’s offset (in pixels) from the
mapPosition()
reference point.See also
Deprecated since version use:
frameOffsetFromReferencePointMm()
instead- Return type:
QPointF
- frameOffsetFromReferencePointMm(self) QPointF ¶
Returns the annotation’s frame’s offset (in millimeters) from the
mapPosition()
reference point.See also
New in version 3.4.8.
- Return type:
QPointF
- frameSize(self) QSizeF ¶
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 use:
frameSizeMm()
instead- Return type:
QSizeF
- frameSizeMm(self) QSizeF ¶
Returns the size (in millimeters) of the annotation’s frame (the main area in which the annotation’s content is drawn).
See also
New in version 3.4.8.
- Return type:
QSizeF
- hasFixedMapPosition(self) bool ¶
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
- isSignalConnected(self, QMetaMethod) bool ¶
- isVisible(self) bool ¶
Returns
True
if the annotation is visible and should be rendered.See also
- Return type:
bool
- mapLayer(self) QgsMapLayer ¶
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:
- mapLayerChanged¶
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
- mapPosition(self) QgsPointXY ¶
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 ¶
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 ¶
Returns the symbol that is drawn at the annotation’s map position.
See also
- Return type:
- minimumFrameSize(self) QSizeF ¶
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
- moved¶
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
- readXml(self, itemElem: QDomElement, context: QgsReadWriteContext)¶
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) –
- receivers(self, PYQT_SIGNAL) int ¶
- relativePosition(self) QPointF ¶
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)¶
Renders the annotation to a target render context.
- Parameters:
context (QgsRenderContext) –
- renderAnnotation(self, context: QgsRenderContext, size: QSizeF)¶
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) –
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setAssociatedFeature(self, feature: QgsFeature)¶
Sets the feature associated with the annotation.
See also
- Parameters:
feature (QgsFeature) –
- setContentsMargin(self, margins: QgsMargins)¶
Sets the margins (in millimeters) between the outside of the frame and the annotation content.
See also
- Parameters:
margins (QgsMargins) –
- setFillSymbol(self, symbol: QgsFillSymbol)¶
Sets the fill symbol used for rendering the annotation frame. Ownership of the symbol is transferred to the annotation.
See also
- Parameters:
symbol (QgsFillSymbol) –
- setFrameOffsetFromReferencePoint(self, offset: QPointF | QPoint | float)¶
Sets the annotation’s frame’s offset (in pixels) from the
mapPosition()
reference point.See also
Deprecated since version use:
setFrameOffsetFromReferencePointMm()
instead- Parameters:
offset (Union[QPointF) –
- setFrameOffsetFromReferencePointMm(self, offset: QPointF | QPoint | float)¶
Sets the annotation’s frame’s offset (in millimeters) from the
mapPosition()
reference point.See also
New in version 3.4.8.
- Parameters:
offset (Union[QPointF) –
- setFrameSize(self, size: QSizeF)¶
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 use:
setFrameSizeMm()
instead- Parameters:
size (QSizeF) –
- setFrameSizeMm(self, size: QSizeF)¶
Sets the size (in millimeters) of the annotation’s frame (the main area in which the annotation’s content is drawn).
See also
New in version 3.4.8.
- Parameters:
size (QSizeF) –
- setHasFixedMapPosition(self, fixed: bool)¶
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)¶
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 (QgsMapLayer) –
- setMapPosition(self, position: QgsPointXY)¶
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)¶
Sets the CRS of the map position.
See also
- Parameters:
crs (QgsCoordinateReferenceSystem) –
- setMarkerSymbol(self, symbol: QgsMarkerSymbol)¶
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 (QgsMarkerSymbol) –
- setRelativePosition(self, position: QPointF | QPoint | float)¶
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) –
- setVisible(self, visible: bool)¶
Sets whether the annotation is visible and should be rendered.
See also
- Parameters:
visible (bool) –
- timerEvent(self, QTimerEvent)¶
- writeXml(self, elem: QDomElement, doc: QDomDocument, context: QgsReadWriteContext)¶
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) –