Class: QgsLayoutItemLabel¶
A layout item subclass for text labels.
Class Hierarchy¶
Base classes¶
Base class for graphical items within a |
|
A base class for objects which belong to a layout. |
|
Abstract interface for generating an expression context. |
|
Interface for layout objects which support undo/redo commands. |
Methods
Resizes the item so that the label's text fits to the item. |
|
Converts the label's |
|
Returns the text as it appears on the label (with evaluated expressions and other dynamic content). |
|
Returns the label's current font. |
|
Returns the label font color. |
|
Returns the horizontal alignment of the label. |
|
Returns the horizontal margin between the edge of the frame and the label contents, in layout units. |
|
Returns the vertical margin between the edge of the frame and the label contents, in layout units. |
|
Returns the label's current mode. |
|
Sets the label's current font. |
|
Sets the label font color. |
|
Sets the horizontal alignment of the label. |
|
Sets the margin between the edge of the frame and the label contents. |
|
Sets the horizontal margin between the edge of the frame and the label contents, in layout units. |
|
Sets the vertical margin between the edge of the frame and the label contents, in layout units. |
|
Sets the label's current mode, allowing the label to switch between font based and HTML based rendering. |
|
Sets the label's preset text. |
|
Sets the text format used for drawing text in the label. |
|
Sets for the vertical alignment of the label. |
|
Returns the required item size (in layout units) for the label's text to fill the item. |
|
Returns the label's preset text. |
|
Returns the text format used for drawing text in the label. |
|
Returns for the vertical alignment of the label. |
Static Methods
Returns a new label item for the specified layout. |
Attributes
- class qgis.core.QgsLayoutItemLabel[source]¶
Bases:
QgsLayoutItem
- __init__(layout: QgsLayout | None)
Constructor for QgsLayoutItemLabel, with the specified parent
layout
.- Parameters:
layout (Optional[QgsLayout])
- class Mode¶
Bases:
int
- ModeFont = 0¶
- ModeHtml = 1¶
- adjustSizeToText(self)[source]¶
Resizes the item so that the label’s text fits to the item. Keeps the top left point stationary.
See also
- adjustSizeToText(self, referencePoint: QgsLayoutItem.ReferencePoint)[source]
Resizes the item so that the label’s text fits to the item.
Keeps the specified reference point stationary.
See also
Added in version 3.42.
- Parameters:
referencePoint (QgsLayoutItem.ReferencePoint)
- convertToStaticText(self)[source]¶
Converts the label’s
text()
to a static string, by evaluating any expressions included in the text and replacing them with their current values.Added in version 3.20.
- static create(layout: QgsLayout | None) QgsLayoutItemLabel | None [source]¶
Returns a new label item for the specified
layout
.The caller takes responsibility for deleting the returned object.
- Parameters:
layout (Optional[QgsLayout])
- Return type:
Optional[QgsLayoutItemLabel]
- currentText(self) str [source]¶
Returns the text as it appears on the label (with evaluated expressions and other dynamic content).
See also
- Return type:
str
- font(self) QFont [source]¶
Returns the label’s current font.
See also
Deprecated since version 3.40: Use
textFormat()
instead (since QGIS 3.24).- Return type:
QFont
- fontColor(self) QColor [source]¶
Returns the label font color.
See also
Deprecated since version 3.40: Use
textFormat()
instead (since QGIS 3.24).- Return type:
QColor
- hAlign(self) Qt.AlignmentFlag [source]¶
Returns the horizontal alignment of the label.
See also
See also
- Return type:
Qt.AlignmentFlag
- marginX(self) float [source]¶
Returns the horizontal margin between the edge of the frame and the label contents, in layout units.
See also
See also
- Return type:
float
- marginY(self) float [source]¶
Returns the vertical margin between the edge of the frame and the label contents, in layout units.
See also
See also
- Return type:
float
- mode(self) QgsLayoutItemLabel.Mode [source]¶
Returns the label’s current mode.
See also
- Return type:
- setFont(self, font: QFont)[source]¶
Sets the label’s current
font
.See also
Deprecated since version 3.40: Use
setTextFormat()
instead (since QGIS 3.24).- Parameters:
font (QFont)
- setFontColor(self, color: QColor | Qt.GlobalColor)[source]¶
Sets the label font
color
.See also
Deprecated since version 3.40: Use
setTextFormat()
instead (since QGIS 3.24).- Parameters:
color (Union[QColor, Qt.GlobalColor])
- setHAlign(self, alignment: Qt.AlignmentFlag)[source]¶
Sets the horizontal
alignment
of the label.See also
See also
- Parameters:
alignment (Qt.AlignmentFlag)
- setMargin(self, margin: float)[source]¶
Sets the
margin
between the edge of the frame and the label contents. This method sets both the horizontal and vertical margins to the same value. The margins can be individually controlled using thesetMarginX()
andsetMarginY()
methods.Margins are set using the current layout units.
See also
See also
- Parameters:
margin (float)
- setMarginX(self, margin: float)[source]¶
Sets the horizontal
margin
between the edge of the frame and the label contents, in layout units.See also
See also
- Parameters:
margin (float)
- setMarginY(self, margin: float)[source]¶
Sets the vertical
margin
between the edge of the frame and the label contents, in layout units.See also
See also
- Parameters:
margin (float)
- setMode(self, mode: QgsLayoutItemLabel.Mode)[source]¶
Sets the label’s current
mode
, allowing the label to switch between font based and HTML based rendering.See also
- Parameters:
mode (QgsLayoutItemLabel.Mode)
- setText(self, text: str | None)[source]¶
Sets the label’s preset
text
.See also
- Parameters:
text (Optional[str])
- setTextFormat(self, format: QgsTextFormat)[source]¶
Sets the text
format
used for drawing text in the label.See also
Added in version 3.24.
- Parameters:
format (QgsTextFormat)
- setVAlign(self, alignment: Qt.AlignmentFlag)[source]¶
Sets for the vertical
alignment
of the label.See also
See also
- Parameters:
alignment (Qt.AlignmentFlag)
- sizeForText(self) QSizeF [source]¶
Returns the required item size (in layout units) for the label’s text to fill the item.
See also
- Return type:
QSizeF
- textFormat(self) QgsTextFormat [source]¶
Returns the text format used for drawing text in the label.
See also
Added in version 3.24.
- Return type: