Subgroup: Layout

Class: QgsLayoutItemLabel

class qgis.core.QgsLayoutItemLabel(layout: QgsLayout)

Bases: qgis._core.QgsLayoutItem

Constructor for QgsLayoutItemLabel, with the specified parent layout.

A layout item subclass for text labels.

New in version 3.0: Methods

adjustPointForReferencePosition
adjustSizeToText Resizes the item so that the label’s text fits to the item.
applyDataDefinedSize
applyItemSizeConstraint
boundingRect
childEvent
connectNotify
contextMenuEvent
create Returns a new label item for the specified layout.
currentText Returns the text as it appears on the label (with evaluated expressions and other dynamic content).
customEvent
disconnectNotify
displayName
dragEnterEvent
dragLeaveEvent
dragMoveEvent
draw
drawBackground
drawDebugRect
drawFrame
dropEvent
focusInEvent
focusOutEvent
font Returns the label’s current font.
fontColor Returns the label font color.
hAlign Returns the horizontal alignment of the label.
hoverEnterEvent
hoverLeaveEvent
hoverMoveEvent
icon
inputMethodEvent
inputMethodQuery
isSignalConnected
itemChange
keyPressEvent
keyReleaseEvent
marginX Returns the horizontal margin between the edge of the frame and the label contents, in layout units.
marginY Returns the vertical margin between the edge of the frame and the label contents, in layout units.
mode Returns the label’s current mode.
mouseDoubleClickEvent
mouseMoveEvent
mousePressEvent
mouseReleaseEvent
positionAtReferencePoint
prepareGeometryChange
readObjectPropertiesFromElement
readPropertiesFromElement
receivers
refresh
refreshBackgroundColor
refreshBlendMode
refreshFrame
refreshItemPosition
refreshItemRotation
refreshItemSize
refreshOpacity
sceneEvent
sceneEventFilter
sender
senderSignalIndex
setFixedSize
setFont Sets the label’s current font.
setFontColor Sets the label font color.
setFrameEnabled
setFrameStrokeWidth
setHAlign Sets the horizontal alignment of the label.
setMargin Sets the margin between the edge of the frame and the label contents.
setMarginX Sets the horizontal margin between the edge of the frame and the label contents, in layout units.
setMarginY Sets the vertical margin between the edge of the frame and the label contents, in layout units.
setMinimumSize
setMode Sets the label’s current mode, allowing the label to switch between font based and HTML based rendering.
setText Sets the label’s preset text.
setVAlign Sets for the vertical alignment of the label.
sizeForText Returns the required item size (in layout units) for the label’s text to fill the item.
text Returns the label’s preset text.
timerEvent
topLeftToReferencePoint
type
updateMicroFocus
vAlign Returns for the vertical alignment of the label.
wheelEvent
writeObjectPropertiesToElement
writePropertiesToElement

Signals

Attributes

ModeFont
ModeHtml
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
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.

currentText(self) → str

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

See also

text()

customEvent()
disconnectNotify()
displayName(self) → str
dragEnterEvent()
dragLeaveEvent()
dragMoveEvent()
draw(self, context: QgsLayoutItemRenderContext)
drawBackground()
drawDebugRect()
drawFrame()
dropEvent()
focusInEvent()
focusOutEvent()
font(self) → QFont

Returns the label’s current font.

See also

setFont()

fontColor(self) → QColor

Returns the label font color.

See also

setFontColor()

hAlign(self) → Qt.AlignmentFlag

Returns the horizontal alignment of the label.

See also

vAlign()

See also

setHAlign()

hoverEnterEvent()
hoverLeaveEvent()
hoverMoveEvent()
icon(self) → 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()

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

mode(self) → QgsLayoutItemLabel.Mode

Returns the label’s current mode.

See also

setMode()

mouseDoubleClickEvent()
mouseMoveEvent()
mousePressEvent()
mouseReleaseEvent()
positionAtReferencePoint()
prepareGeometryChange()
readObjectPropertiesFromElement()
readPropertiesFromElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) → 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()

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

Sets the label font color.

See also

fontColor()

setFrameEnabled(self, drawFrame: bool)
setFrameStrokeWidth(self, strokeWidth: QgsLayoutMeasurement)
setHAlign(self, alignment: Qt.AlignmentFlag)

Sets the horizontal alignment of the label.

See also

hAlign()

See also

setVAlign()

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

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

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

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

setText(self, text: str)

Sets the label’s preset text.

See also

text()

setVAlign(self, alignment: Qt.AlignmentFlag)

Sets for the vertical alignment of the label.

See also

vAlign()

See also

setHAlign()

sizeForText(self) → QSizeF

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

text(self) → str

Returns the label’s preset text.

See also

currentText()

See also

setText()

timerEvent()
topLeftToReferencePoint()
type(self) → int
updateMicroFocus()
vAlign(self) → Qt.AlignmentFlag

Returns for the vertical alignment of the label.

See also

setVAlign()

See also

hAlign()

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