Class: QgsLayoutItemLegend¶
A layout item subclass for map legends.
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. |
- class qgis.core.QgsLayoutItemLegend[source]¶
Bases:
QgsLayoutItem- __init__(layout: QgsLayout | None)
Constructor for QgsLayoutItemLegend, with the specified parent
layout.- Parameters:
layout (Optional[QgsLayout])
- autoUpdateModel(self) bool[source]¶
Returns whether the legend content should auto update to reflect changes in the project’s layer tree.
See also
- Return type:
bool
- autoWrapLinesAfter(self) float[source]¶
Returns the maximum line length (in millimeters) allowed before lines of text in the legend will be automatically word wrapped.
If the returned value is 0, then no automatic wrapping will occur.
See also
Added in version 3.44.
- Return type:
float
- static create(layout: QgsLayout | None) QgsLayoutItemLegend | None[source]¶
Returns a new legend item for the specified
layout.The caller takes responsibility for deleting the returned object.
- Parameters:
layout (Optional[QgsLayout])
- Return type:
Optional[QgsLayoutItemLegend]
- drawRasterStroke(self) bool[source]¶
Returns whether a stroke will be drawn around raster symbol items.
See also
See also
See also
- Return type:
bool
- equalColumnWidth(self) bool[source]¶
Returns whether column widths should be equalized.
See also
- Return type:
bool
- filterByMapItems(self) List[QgsLayoutItemMap]¶
Returns the maps to use when filtering legend content by map extents.
See also
See also
Added in version 3.32.
- Return type:
- fontColor(self) QColor[source]¶
Returns the legend font color.
See also
Deprecated since version 3.40: Use
QgsLegendStyle.setTextFormat()fromstyle()instead.- Return type:
QColor
- legendFilterByMapEnabled(self) bool[source]¶
Find out whether legend items are filtered to show just the ones visible in the associated map
See also
- Return type:
bool
- legendFilterOutAtlas(self) bool[source]¶
Returns whether to filter out legend elements outside of the current atlas feature.
See also
- Return type:
bool
- legendSettings(self) QgsLegendSettings¶
Returns the legend’s renderer settings object.
- Return type:
- lineSpacing(self) float[source]¶
Returns the spacing in-between lines in layout units.
See also
Deprecated since version 3.40: Use
QgsLegendStyle.textFormat()fromstyle()instead.- Return type:
float
- linkedMap(self) QgsLayoutItemMap | None[source]¶
Returns the associated map.
See also
- Return type:
Optional[QgsLayoutItemMap]
- maximumSymbolSize(self) float[source]¶
Returns the maximum symbol size (in mm). 0.0 means there is no maximum set.
See also
Added in version 3.16.
- Return type:
float
- minimumSymbolSize(self) float[source]¶
Returns the minimum symbol size (in mm). A value 0.0 means there is no minimum set.
See also
Added in version 3.16.
- Return type:
float
- model(self) QgsLegendModel | None[source]¶
Returns the legend model.
- Return type:
Optional[QgsLegendModel]
- rasterStrokeColor(self) QColor[source]¶
Returns the stroke color for the stroke drawn around raster symbol items. The stroke is only drawn if
drawRasterStroke()isTrue.See also
See also
See also
- Return type:
QColor
- rasterStrokeWidth(self) float[source]¶
Returns the stroke width (in layout units) for the stroke drawn around raster symbol items. The stroke is only drawn if
drawRasterStroke()isTrue.See also
See also
See also
- Return type:
float
- resizeToContents(self) bool[source]¶
Returns whether the legend should automatically resize to fit its contents.
See also
- Return type:
bool
- rstyle(self, s: Qgis.LegendComponent) QgsLegendStyle¶
Returns reference to modifiable legend style.
- Parameters:
- Return type:
- setAutoUpdateModel(self, autoUpdate: bool)[source]¶
Sets whether the legend content should auto update to reflect changes in the project’s layer tree.
See also
- Parameters:
autoUpdate (bool)
- setAutoWrapLinesAfter(self, length: float)[source]¶
Sets the maximum line
length(in millimeters) allowed before lines of text in the legend will be automatically word wrapped.If
lengthis 0, then no automatic wrapping will occur.See also
Added in version 3.44.
- Parameters:
length (float)
- setBoxSpace(self, space: float)[source]¶
Sets the legend box
space.See also
- Parameters:
space (float)
- setColumnCount(self, count: int)[source]¶
Sets the legend column
count.See also
- Parameters:
count (int)
- setColumnSpace(self, spacing: float)[source]¶
Sets the legend column
spacing.See also
- Parameters:
spacing (float)
- setDrawRasterStroke(self, enabled: bool)[source]¶
Sets whether a stroke will be drawn around raster symbol items.
- Parameters:
enabled (bool) – set to
Trueto draw borders
See also
See also
See also
- setEqualColumnWidth(self, equalize: bool)[source]¶
Sets whether column widths should be equalized.
See also
- Parameters:
equalize (bool)
- setFilterByMapItems(self, maps: Iterable[QgsLayoutItemMap])[source]¶
Sets the
mapsto use when filtering legend content by map extents.See also
See also
Added in version 3.32.
- Parameters:
maps (Iterable[QgsLayoutItemMap])
- setFontColor(self, color: QColor | Qt.GlobalColor)[source]¶
Sets the legend font
color.See also
Deprecated since version 3.40: Use
QgsLegendStyle.setTextFormat()fromstyle()instead.- Parameters:
color (Union[QColor, Qt.GlobalColor])
- setLegendFilterByMapEnabled(self, enabled: bool)[source]¶
Set whether legend items should be filtered to show just the ones visible in the associated map.
See also
- Parameters:
enabled (bool)
- setLegendFilterOutAtlas(self, doFilter: bool)[source]¶
When set to
True, during an atlas rendering, it will filter out legend elements where features are outside the current atlas feature.See also
- Parameters:
doFilter (bool)
- setLineSpacing(self, spacing: float)[source]¶
Sets the
spacingin-between multiple lines.See also
Deprecated since version 3.40: Use
QgsLegendStyle.setTextFormat()fromstyle()instead.- Parameters:
spacing (float)
- setLinkedMap(self, map: QgsLayoutItemMap | None)[source]¶
Sets the
mapto associate with the legend.See also
See also
- Parameters:
map (Optional[QgsLayoutItemMap])
- setMaximumSymbolSize(self, size: float)[source]¶
Set the maximum symbol
sizefor symbol (in millimeters).A symbol size of 0.0 indicates no maximum is set.
See also
Added in version 3.16.
- Parameters:
size (float)
- setMinimumSymbolSize(self, size: float)[source]¶
Set the minimum symbol
sizefor symbol (in millimeters).A symbol size of 0.0 indicates no minimum is set.
See also
Added in version 3.16.
- Parameters:
size (float)
- setRasterStrokeColor(self, color: QColor | Qt.GlobalColor)[source]¶
Sets the stroke
colorfor the stroke drawn around raster symbol items. The stroke is only drawn ifdrawRasterStroke()isTrue.See also
See also
See also
- Parameters:
color (Union[QColor, Qt.GlobalColor])
- setRasterStrokeWidth(self, width: float)[source]¶
Sets the stroke width for the stroke drawn around raster symbol items. The stroke is only drawn if
drawRasterStroke()isTrue.See also
See also
See also
- Parameters:
width (float)
- setResizeToContents(self, enabled: bool)[source]¶
Sets whether the legend should automatically resize to fit its contents.
- Parameters:
enabled (bool) – set to
Falseto disable automatic resizing. The legend frame will not be expanded to fit legend items, and items may be cropped from display.
See also
- setSplitLayer(self, enabled: bool)[source]¶
Sets whether the legend items from a single layer can be split over multiple columns.
See also
- Parameters:
enabled (bool)
- setStyle(self, component: Qgis.LegendComponent, style: QgsLegendStyle)[source]¶
Sets the style of
componenttostylefor the legend.- Parameters:
component (Qgis.LegendComponent)
style (QgsLegendStyle)
- setStyleFont(self, component: Qgis.LegendComponent, font: QFont)[source]¶
Sets the style
fontfor a legendcomponent.See also
Deprecated since version 3.40: Use
QgsLegendStyle.setTextFormat()fromstyle()instead.- Parameters:
component (Qgis.LegendComponent)
font (QFont)
- setStyleMargin(self, component: Qgis.LegendComponent, margin: float)[source]¶
Set the
marginfor a legendcomponent.setStyleMargin(self, component: Qgis.LegendComponent, side: QgsLegendStyle.Side, margin: float) Set the
marginfor a particularsideof a legendcomponent.- Parameters:
component (Qgis.LegendComponent)
margin (float)
- setSymbolAlignment(self, alignment: Qt.AlignmentFlag)[source]¶
Sets the
alignmentfor placement of legend symbols.Only Qt.AlignLeft or Qt.AlignRight are supported values.
See also
Added in version 3.10.
- Parameters:
alignment (Qt.AlignmentFlag)
- setSymbolHeight(self, height: float)[source]¶
Sets the legend symbol
height.See also
- Parameters:
height (float)
- setSymbolWidth(self, width: float)[source]¶
Sets the legend symbol
width.See also
- Parameters:
width (float)
- setTitle(self, title: str | None)[source]¶
Sets the legend
title.See also
- Parameters:
title (Optional[str])
- setTitleAlignment(self, alignment: Qt.AlignmentFlag)[source]¶
Sets the
alignmentof the legend title.See also
- Parameters:
alignment (Qt.AlignmentFlag)
- setWmsLegendHeight(self, height: float)[source]¶
Sets the WMS legend
height.See also
- Parameters:
height (float)
- setWmsLegendWidth(self, width: float)[source]¶
Sets the WMS legend
width.See also
- Parameters:
width (float)
- setWrapString(self, string: str | None)[source]¶
Sets the legend text wrapping
string.See also
- Parameters:
string (Optional[str])
- splitLayer(self) bool[source]¶
Returns whether the legend items from a single layer can be split over multiple columns.
See also
- Return type:
bool
- style(self, s: Qgis.LegendComponent) QgsLegendStyle[source]¶
Returns legend style.
- Parameters:
- Return type:
- styleFont(self, component: Qgis.LegendComponent) QFont[source]¶
Returns the font settings for a legend
component.See also
Deprecated since version 3.40: Use
QgsLegendStyle.textFormat()fromstyle()instead.- Parameters:
component (Qgis.LegendComponent)
- Return type:
QFont
- symbolAlignment(self) Qt.AlignmentFlag[source]¶
Returns the alignment for placement of legend symbols.
Only Qt.AlignLeft or Qt.AlignRight are supported values.
See also
Added in version 3.10.
- Return type:
Qt.AlignmentFlag
- themeName(self) str[source]¶
Returns the name of the theme currently linked to the legend.
This usually equates to the theme rendered in the
linkedMap().Added in version 3.14.
- Return type:
str
- titleAlignment(self) Qt.AlignmentFlag[source]¶
Returns the alignment of the legend title.
See also
- Return type:
Qt.AlignmentFlag
- updateFilterByMap(self, redraw: bool = True)[source]¶
Updates the legend content when filtered by map.
- Parameters:
redraw (bool = True)