Class: QgsScaleBarRenderer

class qgis.core.QgsScaleBarRenderer

Bases: sip.wrapper

Constructor for QgsScaleBarRenderer.

QgsScaleBarRenderer(QgsScaleBarRenderer)

Abstract base class for scale bar renderers.

Scalebar renderer subclasses implement custom drawing logic, with the possibility to implement custom labeling.

Methods

calculateBoxSize

Calculates the required box size (in millimeters) for a scalebar using the specified settings and scaleContext.

draw

Draws the scalebar using the specified settings and scaleContext to a destination render context.

drawDefaultLabels

Draws default scalebar labels using the specified settings and scaleContext to a destination render context.

firstLabelString

Returns the text used for the first label in the scalebar.

firstLabelXOffset

Returns the x-offset (in millimeters) used for the first label in the scalebar.

name

Returns the unique name for this style.

segmentPositions

Returns a list of positions for each segment within the scalebar.

segmentWidths

Returns a list of widths of each segment of the scalebar.

class ScaleBarContext

Bases: sip.wrapper

QgsScaleBarRenderer.ScaleBarContext(QgsScaleBarRenderer.ScaleBarContext)

scale
segmentWidth
size
calculateBoxSize(self, settings: QgsScaleBarSettings, scaleContext: QgsScaleBarRenderer.ScaleBarContext) → QSizeF

Calculates the required box size (in millimeters) for a scalebar using the specified settings and scaleContext.

Parameters
Return type

QSizeF

draw(self, context: QgsRenderContext, settings: QgsScaleBarSettings, scaleContext: QgsScaleBarRenderer.ScaleBarContext)

Draws the scalebar using the specified settings and scaleContext to a destination render context.

Parameters
drawDefaultLabels(self, context: QgsRenderContext, settings: QgsScaleBarSettings, scaleContext: QgsScaleBarRenderer.ScaleBarContext)

Draws default scalebar labels using the specified settings and scaleContext to a destination render context.

Parameters
firstLabelString(self, settings: QgsScaleBarSettings) → str

Returns the text used for the first label in the scalebar.

Parameters

settings (QgsScaleBarSettings) –

Return type

str

firstLabelXOffset(self, settings: QgsScaleBarSettings) → float

Returns the x-offset (in millimeters) used for the first label in the scalebar.

Deprecated since version Use: the version with QgsRenderContext instead.

firstLabelXOffset(self, settings: QgsScaleBarSettings, context: QgsRenderContext, scaleContext: QgsScaleBarRenderer.ScaleBarContext) -> float Returns the x-offset (in render context painter units) used for the first label in the scalebar.

New in version 3.2.

Parameters

settings (QgsScaleBarSettings) –

Return type

float

name(self) → str

Returns the unique name for this style.

Return type

str

segmentPositions(self, scaleContext: QgsScaleBarRenderer.ScaleBarContext, settings: QgsScaleBarSettings) → List[float]

Returns a list of positions for each segment within the scalebar.

Parameters
Return type

List[float]

segmentWidths(self, scaleContext: QgsScaleBarRenderer.ScaleBarContext, settings: QgsScaleBarSettings) → List[float]

Returns a list of widths of each segment of the scalebar.

Parameters
Return type

List[float]