Subgroup: Legend

Class: QgsLegendSettings

class qgis.core.QgsLegendSettings

Bases: sip.wrapper

The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLegendRenderer. The content of the legend is given in QgsLegendModel class.

New in version 2.6: Methods

boxSpace
columnCount
columnSpace
dpi
drawRasterStroke Returns whether a stroke will be drawn around raster symbol items.
drawText Draws Text.
equalColumnWidth
fontAscentMillimeters Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE
fontColor
fontDescentMillimeters Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE
fontHeightCharacterMM Returns the font height of a character in millimeters
lineSpacing
mapScale Returns the legend map scale.
mmPerMapUnit
pixelFontSize Calculates font to from point size to pixel size
rasterStrokeColor Returns the stroke color for the stroke drawn around raster symbol items.
rasterStrokeWidth Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items.
scaledFontPixelSize Returns a font where size is in pixel and font size is upscaled with FONT_WORKAROUND_SCALE
setBoxSpace
setColumnCount
setColumnSpace
setDpi
setDrawRasterStroke Sets whether a stroke will be drawn around raster symbol items.
setEqualColumnWidth
setFontColor
setLineSpacing
setMapScale Sets the legend map scale.
setMmPerMapUnit
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.
setSplitLayer
setStyle
setSymbolSize
setTitle
setTitleAlignment Sets the alignment of the legend title
setUseAdvancedEffects
setWmsLegendSize
setWrapChar
splitLayer
splitStringForWrapping Splits a string using the wrap char taking into account handling empty wrap char which means no wrapping
style Returns style
symbolSize
textWidthMillimeters Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE
title
titleAlignment Returns the alignment of the legend title
useAdvancedEffects
wmsLegendSize
wrapChar

Signals

Attributes

boxSpace(self) → float
columnCount(self) → int
columnSpace(self) → float
dpi(self) → int
drawRasterStroke(self) → bool

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

New in version 2.12.

drawText(self, p: QPainter, x: float, y: float, text: str, font: QFont)

Draws Text. Takes care about all the composer specific issues (calculation to pixel, scaling of font and painter to work around the Qt font bug)

drawText(self, p: QPainter, rect: QRectF, text: str, font: QFont, halignment: Qt.AlignmentFlag = Qt.AlignLeft, valignment: Qt.AlignmentFlag = Qt.AlignTop, flags: int = Qt.TextWordWrap) Like the above, but with a rectangle for multiline text

Parameters:
  • p – painter to use
  • rect – rectangle to draw into
  • text – text to draw
  • font – font to use
  • halignment – optional horizontal alignment
  • valignment – optional vertical alignment
  • flags – allows for passing Qt.TextFlags to control appearance of rendered text
equalColumnWidth(self) → bool
fontAscentMillimeters(self, font: QFont) → float

Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE

fontColor(self) → QColor
fontDescentMillimeters(self, font: QFont) → float

Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE

fontHeightCharacterMM(self, font: QFont, c: str) → float

Returns the font height of a character in millimeters

lineSpacing(self) → float
mapScale(self) → float

Returns the legend map scale. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

See also

setMapScale()

mmPerMapUnit(self) → float
pixelFontSize(self, pointSize: float) → float

Calculates font to from point size to pixel size

rasterStrokeColor(self) → QColor

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

New in version 2.12.

rasterStrokeWidth(self) → float

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

New in version 2.12.

scaledFontPixelSize(self, font: QFont) → QFont

Returns a font where size is in pixel and font size is upscaled with FONT_WORKAROUND_SCALE

setBoxSpace(self, s: float)
setColumnCount(self, c: int)
setColumnSpace(self, s: float)
setDpi(self, dpi: int)
setDrawRasterStroke(self, enabled: bool)

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

Parameters:enabled – set to true to draw borders

New in version 2.12.

setEqualColumnWidth(self, s: bool)
setFontColor(self, c: Union[QColor, Qt.GlobalColor, QGradient])
setLineSpacing(self, s: float)
setMapScale(self, scale: float)

Sets the legend map scale. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

See also

mapScale()

setMmPerMapUnit(self, mmPerMapUnit: float)
setRasterStrokeColor(self, color: Union[QColor, Qt.GlobalColor, QGradient])

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

Parameters:color – stroke color

New in version 2.12.

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.

Parameters:width – stroke width in millimeters

New in version 2.12.

setSplitLayer(self, s: bool)
setStyle(self, s: QgsLegendStyle.Style, style: QgsLegendStyle)
setSymbolSize(self, s: QSizeF)
setTitle(self, t: str)
setTitleAlignment(self, alignment: Qt.AlignmentFlag)

Sets the alignment of the legend title

Parameters:alignment – Text alignment for drawing the legend title

See also

titleAlignment()

setUseAdvancedEffects(self, use: bool)
setWmsLegendSize(self, s: QSizeF)
setWrapChar(self, t: str)
splitLayer(self) → bool
splitStringForWrapping(self, stringToSplt: str) → List[str]

Splits a string using the wrap char taking into account handling empty wrap char which means no wrapping

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

Returns style

symbolSize(self) → QSizeF
textWidthMillimeters(self, font: QFont, text: str) → float

Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE

title(self) → str
titleAlignment(self) → Qt.AlignmentFlag

Returns the alignment of the legend title

Returns:Qt.AlignmentFlag for the legend title
useAdvancedEffects(self) → bool
wmsLegendSize(self) → QSizeF
wrapChar(self) → str