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. |
Methods
Sets the legend's item bounds to fit the whole legend content. |
|
Returns whether the legend content should auto update to reflect changes in the project's layer tree. |
|
Returns the maximum line length (in millimeters) allowed before lines of text in the legend will be automatically word wrapped. |
|
Returns the legend box space. |
|
Returns the legend column count. |
|
Returns the legend column spacing. |
|
Returns whether a stroke will be drawn around raster symbol items. |
|
Returns whether column widths should be equalized. |
|
Returns the maps to use when filtering legend content by map extents. |
|
Returns the legend font color. |
|
Find out whether legend items are filtered to show just the ones visible in the associated map |
|
Returns whether to filter out legend elements outside of the current atlas feature. |
|
Returns the legend's renderer settings object. |
|
Returns the spacing in-between lines in layout units. |
|
Returns the associated map. |
|
Returns the maximum symbol size (in mm). |
|
Returns the minimum symbol size (in mm). |
|
Returns the legend model. |
|
Returns the stroke color for the stroke drawn around raster symbol items. |
|
Returns the stroke width (in layout units) for the stroke drawn around raster symbol items. |
|
Returns whether the legend should automatically resize to fit its contents. |
|
Returns reference to modifiable legend style. |
|
Sets whether the legend content should auto update to reflect changes in the project's layer tree. |
|
Sets the maximum line length (in millimeters) allowed before lines of text in the legend will be automatically word wrapped. |
|
Sets the legend box space. |
|
Sets the legend column count. |
|
Sets the legend column spacing. |
|
Sets whether a stroke will be drawn around raster symbol items. |
|
Sets whether column widths should be equalized. |
|
Sets the maps to use when filtering legend content by map extents. |
|
Sets the legend font color. |
|
Set whether legend items should be filtered to show just the ones visible in the associated map. |
|
When set to |
|
Sets the spacing in-between multiple lines. |
|
Sets the map to associate with the legend. |
|
Set the maximum symbol size for symbol (in millimeters). |
|
Set the minimum symbol size for symbol (in millimeters). |
|
Sets the stroke color for the stroke drawn around raster symbol items. |
|
Sets the stroke width for the stroke drawn around raster symbol items. |
|
Sets whether the legend should automatically resize to fit its contents. |
|
Sets whether the legend items from a single layer can be split over multiple columns. |
|
Sets the style of component to style for the legend. |
|
Sets the style font for a legend component. |
|
Set the margin for a legend component. |
|
Sets the alignment for placement of legend symbols. |
|
Sets the legend symbol height. |
|
Sets the legend symbol width. |
|
Sets the legend title. |
|
Sets the alignment of the legend title. |
|
Sets the WMS legend height. |
|
Sets the WMS legend width. |
|
Sets the legend text wrapping string. |
|
Returns whether the legend items from a single layer can be split over multiple columns. |
|
Returns legend style. |
|
Returns the font settings for a legend component. |
|
Returns the alignment for placement of legend symbols. |
|
Returns the legend symbol height. |
|
Returns the legend symbol width. |
|
Returns the name of the theme currently linked to the legend. |
|
Returns the legend title. |
|
Returns the alignment of the legend title. |
|
Updates the legend content when filtered by map. |
|
Updates the model and all legend entries. |
|
Returns the WMS legend height. |
|
Returns the WMS legend width. |
|
Returns the legend text wrapping string. |
Static Methods
Returns a new legend item for the specified layout. |
- 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:
List[QgsLayoutItemMap]
- 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
length
is 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
True
to 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
maps
to 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
spacing
in-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
map
to associate with the legend.See also
See also
- Parameters:
map (Optional[QgsLayoutItemMap])
- setMaximumSymbolSize(self, size: float)[source]¶
Set the maximum symbol
size
for 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
size
for 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
color
for 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
False
to 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
component
tostyle
for the legend.- Parameters:
component (Qgis.LegendComponent)
style (QgsLegendStyle)
- setStyleFont(self, component: Qgis.LegendComponent, font: QFont)[source]¶
Sets the style
font
for 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
margin
for a legendcomponent
.- Parameters:
component (Qgis.LegendComponent)
margin (float)
- setStyleMargin(self, component: Qgis.LegendComponent, side: QgsLegendStyle.Side, margin: float)[source]
Set the
margin
for a particularside
of a legendcomponent
.- Parameters:
component (Qgis.LegendComponent)
side (QgsLegendStyle.Side)
margin (float)
- setSymbolAlignment(self, alignment: Qt.AlignmentFlag)[source]¶
Sets the
alignment
for 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
alignment
of 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)