Class: QgsLayoutItemLegend

class qgis.core.QgsLayoutItemLegend(layout: QgsLayout)

Bases: qgis._core.QgsLayoutItem

Constructor for QgsLayoutItemLegend, with the specified parent layout.

A layout item subclass for map legends.

New in version 3.0: Enums

Methods

adjustBoxSize

Sets the legend’s item bounds to fit the whole legend content.

adjustPointForReferencePosition

applyDataDefinedSize

applyItemSizeConstraint

autoUpdateModel

Returns whether the legend content should auto update to reflect changes in the project’s layer tree.

boxSpace

Returns the legend box space.

childEvent

columnCount

Returns the legend column count.

columnSpace

Returns the legend column spacing.

connectNotify

contextMenuEvent

create

Returns a new legend item for the specified layout.

customEvent

disconnectNotify

displayName

dragEnterEvent

dragLeaveEvent

dragMoveEvent

draw

drawBackground

drawDebugRect

drawFrame

drawRasterStroke

Returns whether a stroke will be drawn around raster symbol items.

dropEvent

equalColumnWidth

Returns whether column widths should be equalized.

finalizeRestoreFromXml

focusInEvent

focusOutEvent

fontColor

Returns the legend font color.

hoverEnterEvent

hoverLeaveEvent

hoverMoveEvent

icon

inputMethodEvent

inputMethodQuery

isSignalConnected

itemChange

itemFlags

keyPressEvent

keyReleaseEvent

legendFilterByMapEnabled

Find out whether legend items are filtered to show just the ones visible in the associated map

legendFilterOutAtlas

Returns whether to filter out legend elements outside of the current atlas feature.

legendSettings

Returns the legend’s renderer settings object.

lineSpacing

Returns the spacing in-between lines in layout units.

linkedMap

Returns the associated map.

model

Returns the legend model.

mouseDoubleClickEvent

mouseMoveEvent

mousePressEvent

mouseReleaseEvent

paint

positionAtReferencePoint

prepareGeometryChange

rasterStrokeColor

Returns the stroke color for the stroke drawn around raster symbol items.

rasterStrokeWidth

Returns the stroke width (in layout units) for the stroke drawn around raster symbol items.

readObjectPropertiesFromElement

readPropertiesFromElement

receivers

refresh

refreshBackgroundColor

refreshBlendMode

refreshDataDefinedProperty

refreshFrame

refreshItemPosition

refreshItemRotation

refreshItemSize

refreshOpacity

resizeToContents

Returns whether the legend should automatically resize to fit its contents.

rstyle

Returns reference to modifiable legend style.

sceneEvent

sceneEventFilter

sender

senderSignalIndex

setAutoUpdateModel

Sets whether the legend content should auto update to reflect changes in the project’s layer tree.

setBoxSpace

Sets the legend box space.

setColumnCount

Sets the legend column count.

setColumnSpace

Sets the legend column spacing.

setDrawRasterStroke

Sets whether a stroke will be drawn around raster symbol items.

setEqualColumnWidth

Sets whether column widths should be equalized.

setFixedSize

setFontColor

Sets the legend font color.

setLegendFilterByMapEnabled

Set whether legend items should be filtered to show just the ones visible in the associated map.

setLegendFilterOutAtlas

When set to true, during an atlas rendering, it will filter out legend elements where features are outside the current atlas feature.

setLineSpacing

Sets the spacing in-between multiple lines.

setLinkedMap

Sets the map to associate with the legend.

setMinimumSize

setRasterStrokeColor

Sets the stroke color for the stroke drawn around raster symbol items.

setRasterStrokeWidth

Sets the stroke width for the stroke drawn around raster symbol items.

setResizeToContents

Sets whether the legend should automatically resize to fit its contents.

setSplitLayer

Sets whether the legend items from a single layer can be split over multiple columns.

setStyle

Sets the style of component to style for the legend.

setStyleFont

Sets the style font for a legend component.

setStyleMargin

Set the margin for a legend component.

setSymbolHeight

Sets the legend symbol height.

setSymbolWidth

Sets the legend symbol width.

setTitle

Sets the legend title.

setTitleAlignment

Sets the alignment of the legend title.

setWmsLegendHeight

Sets the WMS legend height.

setWmsLegendWidth

Sets the WMS legend width.

setWrapString

Sets the legend text wrapping string.

splitLayer

Returns whether the legend items from a single layer can be split over multiple columns.

style

Returns legend style.

styleFont

Returns the font settings for a legend component.

symbolHeight

Returns the legend symbol height.

symbolWidth

Returns the legend symbol width.

timerEvent

title

Returns the legend title.

titleAlignment

Returns the alignment of the legend title.

topLeftToReferencePoint

type

updateFilterByMap

Updates the legend content when filtered by map.

updateLegend

Updates the model and all legend entries.

updateMicroFocus

wheelEvent

wmsLegendHeight

Returns the WMS legend height.

wmsLegendWidth

Returns the WMS legend width.

wrapString

Returns the legend text wrapping string.

writeObjectPropertiesToElement

writePropertiesToElement

Signals

Attributes

adjustBoxSize(self)

Sets the legend’s item bounds to fit the whole legend content.

adjustPointForReferencePosition()
applyDataDefinedSize()
applyItemSizeConstraint()
autoUpdateModel(self) → bool

Returns whether the legend content should auto update to reflect changes in the project’s layer tree.

boxSpace(self) → float

Returns the legend box space.

See also

setBoxSpace()

childEvent()
columnCount(self) → int

Returns the legend column count.

See also

setColumnCount()

columnSpace(self) → float

Returns the legend column spacing.

See also

setColumnSpace()

connectNotify()
contextMenuEvent()
create(layout: QgsLayout) → QgsLayoutItemLegend

Returns a new legend item for the specified layout.

The caller takes responsibility for deleting the returned object.

customEvent()
disconnectNotify()
displayName(self) → str
dragEnterEvent()
dragLeaveEvent()
dragMoveEvent()
draw(self, context: QgsLayoutItemRenderContext)
drawBackground()
drawDebugRect()
drawFrame()
drawRasterStroke(self) → bool

Returns whether a stroke will be drawn around raster symbol items.

dropEvent()
equalColumnWidth(self) → bool

Returns whether column widths should be equalized.

finalizeRestoreFromXml(self)
focusInEvent()
focusOutEvent()
fontColor(self) → QColor

Returns the legend font color.

See also

setFontColor()

hoverEnterEvent()
hoverLeaveEvent()
hoverMoveEvent()
icon(self) → QIcon
inputMethodEvent()
inputMethodQuery()
isSignalConnected()
itemChange()
itemFlags(self) → QgsLayoutItem.Flags
keyPressEvent()
keyReleaseEvent()
legendFilterByMapEnabled(self) → bool

Find out whether legend items are filtered to show just the ones visible in the associated map

legendFilterOutAtlas(self) → bool

Returns whether to filter out legend elements outside of the current atlas feature.

legendSettings(self) → QgsLegendSettings

Returns the legend’s renderer settings object.

lineSpacing(self) → float

Returns the spacing in-between lines in layout units.

See also

setLineSpacing()

linkedMap(self) → QgsLayoutItemMap

Returns the associated map.

See also

setLinkedMap()

model(self) → QgsLegendModel

Returns the legend model.

mouseDoubleClickEvent()
mouseMoveEvent()
mousePressEvent()
mouseReleaseEvent()
paint(self, painter: QPainter, itemStyle: QStyleOptionGraphicsItem, pWidget: QWidget)
positionAtReferencePoint()
prepareGeometryChange()
rasterStrokeColor(self) → QColor

Returns the stroke color for the stroke drawn around raster symbol items. The stroke is only drawn if drawRasterStroke() is true.

rasterStrokeWidth(self) → float

Returns the stroke width (in layout units) for the stroke drawn around raster symbol items. The stroke is only drawn if drawRasterStroke() is true.

readObjectPropertiesFromElement()
readPropertiesFromElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) → bool
receivers()
refresh(self)
refreshBackgroundColor()
refreshBlendMode()
refreshDataDefinedProperty(self, property: QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.AllProperties)
refreshFrame()
refreshItemPosition()
refreshItemRotation()
refreshItemSize()
refreshOpacity()
resizeToContents(self) → bool

Returns whether the legend should automatically resize to fit its contents.

rstyle(self, s: QgsLegendStyle.Style) → QgsLegendStyle

Returns reference to modifiable legend style.

sceneEvent()
sceneEventFilter()
sender()
senderSignalIndex()
setAutoUpdateModel(self, autoUpdate: bool)

Sets whether the legend content should auto update to reflect changes in the project’s layer tree.

setBoxSpace(self, space: float)

Sets the legend box space.

See also

boxSpace()

setColumnCount(self, count: int)

Sets the legend column count.

See also

columnCount()

setColumnSpace(self, spacing: float)

Sets the legend column spacing.

See also

columnSpace()

setDrawRasterStroke(self, enabled: bool)

Sets whether a stroke will be drawn around raster symbol items.

Parameters

enabled – set to true to draw borders

setEqualColumnWidth(self, equalize: bool)

Sets whether column widths should be equalized.

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

Sets the legend font color.

See also

fontColor()

setLegendFilterByMapEnabled(self, enabled: bool)

Set whether legend items should be filtered to show just the ones visible in the associated map.

setLegendFilterOutAtlas(self, doFilter: bool)

When set to true, during an atlas rendering, it will filter out legend elements where features are outside the current atlas feature.

setLineSpacing(self, spacing: float)

Sets the spacing in-between multiple lines.

See also

lineSpacing()

setLinkedMap(self, map: QgsLayoutItemMap)

Sets the map to associate with the legend.

See also

linkedMap()

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

Sets the stroke color for the stroke drawn around raster symbol items. The stroke is only drawn if drawRasterStroke() is true.

setRasterStrokeWidth(self, width: float)

Sets the stroke width for the stroke drawn around raster symbol items. The stroke is only drawn if drawRasterStroke() is true.

setResizeToContents(self, enabled: bool)

Sets whether the legend should automatically resize to fit its contents.

Parameters

enabled – set to false to disable automatic resizing. The legend frame will not be expanded to fit legend items, and items may be cropped from display.

setSplitLayer(self, enabled: bool)

Sets whether the legend items from a single layer can be split over multiple columns.

See also

splitLayer()

setStyle(self, component: QgsLegendStyle.Style, style: QgsLegendStyle)

Sets the style of component to style for the legend.

setStyleFont(self, component: QgsLegendStyle.Style, font: QFont)

Sets the style font for a legend component.

See also

styleFont()

setStyleMargin(self, component: QgsLegendStyle.Style, margin: float)

Set the margin for a legend component.

setStyleMargin(self, component: QgsLegendStyle.Style, side: QgsLegendStyle.Side, margin: float) Set the margin for a particular side of a legend component.

setSymbolHeight(self, height: float)

Sets the legend symbol height.

See also

symbolHeight()

setSymbolWidth(self, width: float)

Sets the legend symbol width.

See also

symbolWidth()

setTitle(self, title: str)

Sets the legend title.

See also

title()

setTitleAlignment(self, alignment: Qt.AlignmentFlag)

Sets the alignment of the legend title.

See also

titleAlignment()

setWmsLegendHeight(self, height: float)

Sets the WMS legend height.

setWmsLegendWidth(self, width: float)

Sets the WMS legend width.

See also

wmsLegendWidth()

setWrapString(self, string: str)

Sets the legend text wrapping string.

See also

wrapString()

splitLayer(self) → bool

Returns whether the legend items from a single layer can be split over multiple columns.

See also

setSplitLayer()

style(self, s: QgsLegendStyle.Style) → QgsLegendStyle

Returns legend style.

styleFont(self, component: QgsLegendStyle.Style) → QFont

Returns the font settings for a legend component.

See also

setStyleFont()

symbolHeight(self) → float

Returns the legend symbol height.

symbolWidth(self) → float

Returns the legend symbol width.

See also

setSymbolWidth()

timerEvent()
title(self) → str

Returns the legend title.

See also

setTitle()

titleAlignment(self) → Qt.AlignmentFlag

Returns the alignment of the legend title.

topLeftToReferencePoint()
type(self) → int
updateFilterByMap(self, redraw: bool = True)

Updates the legend content when filtered by map.

updateLegend(self)

Updates the model and all legend entries.

updateMicroFocus()
wheelEvent()
wmsLegendHeight(self) → float

Returns the WMS legend height.

wmsLegendWidth(self) → float

Returns the WMS legend width.

wrapString(self) → str

Returns the legend text wrapping string.

See also

setWrapString()

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