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.

New in version 3.0: Enums

Flag

Bases: enum.IntEnum

Methods

applyDefaultSettings

Applies any default settings relating to the scalebar to the passed settings object.

calculateBoxSize

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

clone

Returns a clone of the renderer.

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.

flags

Returns the scalebar rendering flags, which dictates the renderer’s behavior.

id

Returns the unique ID for this renderer.

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.

sortKey

Returns a sorting key value, where renderers with a lower sort key will be shown earlier in lists.

visibleName

Returns the user friendly, translated name for the renderer.

class Flag

Bases: enum.IntEnum

Flags which control scalebar renderer behavior.

New in version 3.14.

  • FlagUsesLineSymbol: Renderer utilizes the scalebar line symbol (see QgsScaleBarSettings::lineSymbol() )

  • FlagUsesFillSymbol: Renderer utilizes the scalebar fill symbol (see QgsScaleBarSettings::fillSymbol() )

  • FlagUsesAlternateFillSymbol: Renderer utilizes the alternate scalebar fill symbol (see QgsScaleBarSettings::alternateFillSymbol() )

  • FlagRespectsUnits: Renderer respects the QgsScaleBarSettings::units() setting

  • FlagRespectsMapUnitsPerScaleBarUnit: Renderer respects the QgsScaleBarSettings::mapUnitsPerScaleBarUnit() setting

  • FlagUsesUnitLabel: Renderer uses the QgsScaleBarSettings::unitLabel() setting

  • FlagUsesSegments: Renderer uses the scalebar segments

  • FlagUsesLabelBarSpace: Renderer uses the QgsScaleBarSettings::labelBarSpace() setting

  • FlagUsesLabelVerticalPlacement: Renderer uses the QgsScaleBarSettings::labelHorizontalPlacement() setting

  • FlagUsesLabelHorizontalPlacement: Renderer uses the QgsScaleBarSettings::labelHorizontalPlacement() setting

  • FlagUsesAlignment: Renderer uses the QgsScaleBarSettings::alignment() setting

FlagRespectsMapUnitsPerScaleBarUnit = 16
FlagRespectsUnits = 8
FlagUsesAlignment = 512
FlagUsesAlternateFillSymbol = 4
FlagUsesFillSymbol = 2
FlagUsesLabelBarSpace = 128
FlagUsesLabelHorizontalPlacement = 256
FlagUsesLabelVerticalPlacement = 256
FlagUsesLineSymbol = 1
FlagUsesSegments = 64
FlagUsesUnitLabel = 32
class Flags

Bases: sip.wrapper

QgsScaleBarRenderer.Flags(Union[QgsScaleBarRenderer.Flags, QgsScaleBarRenderer.Flag]) QgsScaleBarRenderer.Flags(QgsScaleBarRenderer.Flags)

class ScaleBarContext

Bases: sip.wrapper

QgsScaleBarRenderer.ScaleBarContext(QgsScaleBarRenderer.ScaleBarContext)

scale
segmentWidth
size
applyDefaultSettings(self, settings: QgsScaleBarSettings) → bool

Applies any default settings relating to the scalebar to the passed settings object.

Returns True if settings were applied.

New in version 3.14.

Parameters

settings (QgsScaleBarSettings) –

Return type

bool

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

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

Deprecated since version Use: the version with a QgsRenderContext instead.

calculateBoxSize(self, context: QgsRenderContext, settings: QgsScaleBarSettings, scaleContext: QgsScaleBarRenderer.ScaleBarContext) -> QSizeF Calculates the required box size (in millimeters) for a scalebar using the specified settings and scaleContext.

New in version 3.14.

Parameters
Return type

QSizeF

clone(self)QgsScaleBarRenderer

Returns a clone of the renderer. The caller takes ownership of the returned value.

Return type

QgsScaleBarRenderer

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

flags(self) → QgsScaleBarRenderer.Flags

Returns the scalebar rendering flags, which dictates the renderer’s behavior.

New in version 3.14.

Return type

QgsScaleBarRenderer.Flags

id(self) → str

Returns the unique ID for this renderer.

New in version 3.14.

Return type

str

name(self) → str

Returns the unique name for this style.

Deprecated since version use: id() instead

Return type

str

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

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

Deprecated since version use: the version with a QgsRenderContext instead

segmentPositions(self, context: QgsRenderContext, scaleContext: QgsScaleBarRenderer.ScaleBarContext, settings: QgsScaleBarSettings) -> List[float] Returns a list of positions for each segment within the scalebar.

New in version 3.14.

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]

sortKey(self) → int

Returns a sorting key value, where renderers with a lower sort key will be shown earlier in lists.

Generally, subclasses should return QgsScaleBarRenderer.sortKey() as their sorting key.

Return type

int

visibleName(self) → str

Returns the user friendly, translated name for the renderer.

New in version 3.14.

Return type

str