Class: QgsLayoutItemLabel

class qgis.core.QgsLayoutItemLabel(layout: QgsLayout)

Bases: QgsLayoutItem

Constructor for QgsLayoutItemLabel, with the specified parent layout.

A layout item subclass for text labels.

New in version 3.0.

Parameters

layout

class Mode

Bases: int

ModeFont = 0
ModeHtml = 1
adjustPointForReferencePosition()
adjustSizeToText(self)

Resizes the item so that the label’s text fits to the item. Keeps the top left point stationary.

See also

sizeForText()

applyDataDefinedSize()
applyItemSizeConstraint()
boundingRect(self) → QRectF
Return type

QRectF

childEvent()
connectNotify()
contextMenuEvent()
create(layout: QgsLayout) → QgsLayoutItemLabel

Returns a new label item for the specified layout.

The caller takes responsibility for deleting the returned object.

Parameters

layout (QgsLayout) –

Return type

QgsLayoutItemLabel

currentText(self) → str

Returns the text as it appears on the label (with evaluated expressions and other dynamic content).

See also

text()

Return type

str

customEvent()
disconnectNotify()
displayName(self) → str
Return type

str

dragEnterEvent()
dragLeaveEvent()
dragMoveEvent()
draw(self, context: QgsLayoutItemRenderContext)
Parameters

context (QgsLayoutItemRenderContext) –

drawBackground()
drawDebugRect()
drawFrame()
dropEvent()
focusInEvent()
focusOutEvent()
font(self) → QFont

Returns the label’s current font.

See also

setFont()

Return type

QFont

fontColor(self) → QColor

Returns the label font color.

See also

setFontColor()

Return type

QColor

hAlign(self) → Qt.AlignmentFlag

Returns the horizontal alignment of the label.

See also

vAlign()

See also

setHAlign()

Return type

Qt.AlignmentFlag

hoverEnterEvent()
hoverLeaveEvent()
hoverMoveEvent()
icon(self) → QIcon
Return type

QIcon

inputMethodEvent()
inputMethodQuery()
isSignalConnected()
itemChange()
keyPressEvent()
keyReleaseEvent()
marginX(self) → float

Returns the horizontal margin between the edge of the frame and the label contents, in layout units.

See also

setMargin()

See also

marginY()

Return type

float

marginY(self) → float

Returns the vertical margin between the edge of the frame and the label contents, in layout units.

See also

setMargin()

See also

marginX()

Return type

float

mode(self) → QgsLayoutItemLabel.Mode

Returns the label’s current mode.

See also

setMode()

Return type

QgsLayoutItemLabel.Mode

mouseDoubleClickEvent()
mouseMoveEvent()
mousePressEvent()
mouseReleaseEvent()
positionAtReferencePoint()
prepareGeometryChange()
readObjectPropertiesFromElement()
readPropertiesFromElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) → bool
Parameters
Return type

bool

receivers()
refresh(self)
refreshBackgroundColor()
refreshBlendMode()
refreshFrame()
refreshItemPosition()
refreshItemRotation()
refreshItemSize()
refreshOpacity()
sceneEvent()
sceneEventFilter()
sender()
senderSignalIndex()
setFixedSize()
setFont(self, font: QFont)

Sets the label’s current font.

See also

font()

Parameters

font (QFont) –

setFontColor(self, color: Union[QColor, Qt.GlobalColor])

Sets the label font color.

See also

fontColor()

Parameters

color (Union[QColor) –

setFrameEnabled(self, drawFrame: bool)
Parameters

drawFrame (bool) –

setFrameStrokeWidth(self, strokeWidth: QgsLayoutMeasurement)
Parameters

strokeWidth (QgsLayoutMeasurement) –

setHAlign(self, alignment: Qt.AlignmentFlag)

Sets the horizontal alignment of the label.

See also

hAlign()

See also

setVAlign()

Parameters

alignment (Qt.AlignmentFlag) –

setMargin(self, margin: float)

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 the setMarginX() and setMarginY() methods.

Margins are set using the current layout units.

See also

setMarginX()

See also

setMarginY()

Parameters

margin (float) –

setMarginX(self, margin: float)

Sets the horizontal margin between the edge of the frame and the label contents, in layout units.

See also

setMargin()

See also

setMarginY()

Parameters

margin (float) –

setMarginY(self, margin: float)

Sets the vertical margin between the edge of the frame and the label contents, in layout units.

See also

setMargin()

See also

setMarginX()

Parameters

margin (float) –

setMinimumSize()
setMode(self, mode: QgsLayoutItemLabel.Mode)

Sets the label’s current mode, allowing the label to switch between font based and HTML based rendering.

See also

mode()

Parameters

mode (QgsLayoutItemLabel.Mode) –

setText(self, text: str)

Sets the label’s preset text.

See also

text()

Parameters

text (str) –

setVAlign(self, alignment: Qt.AlignmentFlag)

Sets for the vertical alignment of the label.

See also

vAlign()

See also

setHAlign()

Parameters

alignment (Qt.AlignmentFlag) –

sizeForText(self) → QSizeF

Returns the required item size (in layout units) for the label’s text to fill the item.

Return type

QSizeF

text(self) → str

Returns the label’s preset text.

See also

currentText()

See also

setText()

Return type

str

timerEvent()
topLeftToReferencePoint()
type(self) → int
Return type

int

updateMicroFocus()
vAlign(self) → Qt.AlignmentFlag

Returns for the vertical alignment of the label.

See also

setVAlign()

See also

hAlign()

Return type

Qt.AlignmentFlag

wheelEvent()
writeObjectPropertiesToElement()
writePropertiesToElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) → bool
Parameters
Return type

bool