Class: QgsLayoutItemScaleBar

class qgis.core.QgsLayoutItemScaleBar(layout: QgsLayout)

Bases: QgsLayoutItem

Constructor for QgsLayoutItemScaleBar, with the specified parent layout.

A layout item subclass for scale bars.

New in version 3.0.

Parameters

layout

adjustPointForReferencePosition()
alignment(self) → QgsScaleBarSettings.Alignment

Returns the scalebar alignment.

See also

setAlignment()

Return type

QgsScaleBarSettings.Alignment

applyDataDefinedSize()
applyDefaultSettings(self)

Applies the default scalebar settings to the scale bar.

applyDefaultSize(self, units: QgsUnitTypes.DistanceUnit = QgsUnitTypes.DistanceMeters)

Applies the default size to the scale bar (scale bar 1/5 of map item width)

Parameters

units (QgsUnitTypes.DistanceUnit = QgsUnitTypes.DistanceMeters) –

applyItemSizeConstraint()
boxContentSpace(self) → float

Returns the spacing (margin) between the scalebar box and content in millimeters.

Return type

float

brush(self) → QBrush

Returns the primary brush for the scalebar.

Return type

QBrush

Returns

QBrush used for filling the scalebar

See also

brush2()

See also

pen()

brush2(self) → QBrush

Returns the secondary brush for the scalebar. This is used for alternating color style scalebars, such as single and double box styles.

Return type

QBrush

Returns

QBrush used for secondary color areas

See also

brush()

childEvent()
connectNotify()
contextMenuEvent()
create(layout: QgsLayout) → QgsLayoutItemScaleBar

Returns a new scale bar item for the specified layout.

The caller takes responsibility for deleting the returned object.

Parameters

layout (QgsLayout) –

Return type

QgsLayoutItemScaleBar

customEvent()
disconnectNotify()
dragEnterEvent()
dragLeaveEvent()
dragMoveEvent()
draw(self, context: QgsLayoutItemRenderContext)
Parameters

context (QgsLayoutItemRenderContext) –

drawBackground()
drawDebugRect()
drawFrame()
dropEvent()
fillColor(self) → QColor

Returns the color used for fills in the scalebar.

See also

setFillColor()

See also

fillColor2()

Return type

QColor

fillColor2(self) → QColor

Returns the secondary color used for fills in the scalebar.

See also

setFillColor2()

See also

fillColor()

Return type

QColor

finalizeRestoreFromXml(self)
focusInEvent()
focusOutEvent()
font(self) → QFont

Returns the font used for drawing text in the scalebar.

See also

setFont()

Deprecated since version use: textFormat() instead

Return type

QFont

fontColor(self) → QColor

Returns the color used for drawing text in the scalebar.

See also

setFontColor()

See also

font()

Deprecated since version use: textFormat() instead

Return type

QColor

guessUnits(self) → QgsUnitTypes.DistanceUnit

Attempts to guess the most reasonable unit choice for the scalebar, given the current linked map’s scale.

This method also considers the linked map’s CRS, in order to determine if metric or imperial units are more appropriate.

Return type

QgsUnitTypes.DistanceUnit

height(self) → float

Returns the scalebar height (in millimeters).

See also

setHeight()

Return type

float

hoverEnterEvent()
hoverLeaveEvent()
hoverMoveEvent()
icon(self) → QIcon
Return type

QIcon

inputMethodEvent()
inputMethodQuery()
isSignalConnected()
itemChange()
keyPressEvent()
keyReleaseEvent()
labelBarSpace(self) → float

Returns the spacing (in millimeters) between labels and the scalebar.

Return type

float

lineCapStyle(self) → Qt.PenCapStyle

Returns the cap style used for drawing lines in the scalebar.

Return type

Qt.PenCapStyle

lineColor(self) → QColor

Returns the color used for lines in the scalebar.

See also

setLineColor()

Return type

QColor

lineJoinStyle(self) → Qt.PenJoinStyle

Returns the join style used for drawing lines in the scalebar.

Return type

Qt.PenJoinStyle

lineWidth(self) → float

Returns the line width in millimeters for lines in the scalebar.

See also

setLineWidth()

Return type

float

linkedMap(self) → QgsLayoutItemMap

Returns the map item linked to the scalebar.

See also

setLinkedMap()

Return type

QgsLayoutItemMap

mapUnitsPerScaleBarUnit(self) → float

Returns the number of map units per scale bar unit used by the scalebar.

Return type

float

maximumBarWidth(self) → float

Returns the maximum width (in millimeters) for scale bar segments. This property is only effective if the segmentSizeMode() is set to SegmentSizeFitWidth.

Return type

float

minimumBarWidth(self) → float

Returns the minimum width (in millimeters) for scale bar segments. This property is only effective if the segmentSizeMode() is set to SegmentSizeFitWidth.

Return type

float

minimumSize(self) → QgsLayoutSize
Return type

QgsLayoutSize

mouseDoubleClickEvent()
mouseMoveEvent()
mousePressEvent()
mouseReleaseEvent()
numberOfSegments(self) → int

Returns the number of segments included in the scalebar.

Return type

int

numberOfSegmentsLeft(self) → int

Returns the number of segments included in the left part of the scalebar.

Return type

int

pen(self) → QPen

Returns the pen used for drawing outlines in the scalebar.

See also

brush()

Return type

QPen

positionAtReferencePoint()
prepareGeometryChange()
readObjectPropertiesFromElement()
readPropertiesFromElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) → bool
Parameters
Return type

bool

receivers()
refreshBackgroundColor()
refreshBlendMode()
refreshDataDefinedProperty(self, property: QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.AllProperties)
Parameters

property (QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.AllProperties) –

refreshFrame()
refreshItemPosition()
refreshItemRotation()
refreshItemSize()
refreshOpacity()
resizeToMinimumWidth(self)

Resizes the scale bar to its minimum width, without changing the height.

sceneEvent()
sceneEventFilter()
segmentSizeMode(self) → QgsScaleBarSettings.SegmentSizeMode

Returns the size mode for the scale bar segments.

Return type

QgsScaleBarSettings.SegmentSizeMode

sender()
senderSignalIndex()
setAlignment(self, alignment: QgsScaleBarSettings.Alignment)

Sets the scalebar alignment.

See also

alignment()

Parameters

alignment (QgsScaleBarSettings.Alignment) –

setBoxContentSpace(self, space: float)

Sets the space (margin) between the scalebar box and content in millimeters.

Parameters

space (float) –

setFillColor(self, color: Union[QColor, Qt.GlobalColor])

Sets the color used for fills in the scalebar.

See also

fillColor()

See also

setFillColor2()

Parameters

color (Union[QColor) –

setFillColor2(self, color: Union[QColor, Qt.GlobalColor])

Sets the secondary color used for fills in the scalebar.

See also

fillColor2()

See also

setFillColor2()

Parameters

color (Union[QColor) –

setFixedSize()
setFont(self, font: QFont)

Sets the font used for drawing text in the scalebar.

See also

font()

Deprecated since version use: setTextFormat() instead

Parameters

font (QFont) –

setFontColor(self, color: Union[QColor, Qt.GlobalColor])

Sets the color used for drawing text in the scalebar.

See also

fontColor()

See also

setFont()

Deprecated since version use: setTextFormat() instead

Parameters

color (Union[QColor) –

setHeight(self, height: float)

Sets the scalebar height (in millimeters).

See also

height()

Parameters

height (float) –

setLabelBarSpace(self, space: float)

Sets the spacing (in millimeters) between labels and the scalebar.

See also

labelBarSpace()

Parameters

space (float) –

setLineCapStyle(self, style: Qt.PenCapStyle)

Sets the cap style used when drawing the lines in the scalebar.

See also

lineCapStyle()

Parameters

style (Qt.PenCapStyle) –

setLineColor(self, color: Union[QColor, Qt.GlobalColor])

Sets the color used for lines in the scalebar.

See also

lineColor()

Parameters

color (Union[QColor) –

setLineJoinStyle(self, style: Qt.PenJoinStyle)

Sets the join style used when drawing the lines in the scalebar

See also

lineJoinStyle()

Parameters

style (Qt.PenJoinStyle) –

setLineWidth(self, width: float)

Sets the line width in millimeters for lines in the scalebar.

See also

lineWidth()

Parameters

width (float) –

setLinkedMap(self, map: QgsLayoutItemMap)

Sets the map item linked to the scalebar.

See also

linkedMap()

Parameters

map (QgsLayoutItemMap) –

setMapUnitsPerScaleBarUnit(self, units: float)

Sets the number of map units per scale bar unit used by the scalebar.

Parameters

units (float) –

setMaximumBarWidth(self, maxWidth: float)

Sets the maximum width (in millimeters) for scale bar segments. This property is only effective if the segmentSizeMode() is set to SegmentSizeFitWidth.

Parameters

maxWidth (float) –

setMinimumBarWidth(self, minWidth: float)

Sets the minimum width (in millimeters) for scale bar segments. This property is only effective if the segmentSizeMode() is set to SegmentSizeFitWidth.

Parameters

minWidth (float) –

setMinimumSize()
setNumberOfSegments(self, segments: int)

Sets the number of segments included in the scalebar.

Parameters

segments (int) –

setNumberOfSegmentsLeft(self, segments: int)

Sets the number of segments included in the left part of the scalebar.

Parameters

segments (int) –

setSegmentSizeMode(self, mode: QgsScaleBarSettings.SegmentSizeMode)

Sets the size mode for scale bar segments.

Parameters

mode (QgsScaleBarSettings.SegmentSizeMode) –

setStyle(self, name: str)

Sets the scale bar style by name.

The name parameter gives the (untranslated) style name. Possibilities are: ‘Single Box’, ‘Double Box’, ‘Line Ticks Middle’, ‘Line Ticks Down’, ‘Line Ticks Up’, ‘Numeric’

See also

style()

Parameters

name (str) –

setTextFormat(self, format: QgsTextFormat)

Sets the text format used for drawing text in the scalebar.

See also

textFormat()

New in version 3.2.

Parameters

format (QgsTextFormat) –

setUnitLabel(self, label: str)

Sets the label for units.

See also

unitLabel()

Parameters

label (str) –

setUnits(self, units: QgsUnitTypes.DistanceUnit)

Sets the distance units used by the scalebar.

See also

units()

Parameters

units (QgsUnitTypes.DistanceUnit) –

setUnitsPerSegment(self, units: float)

Sets the number of scalebar units per segment.

Parameters

units (float) –

style(self) → str

Returns the scale bar style name.

See also

setStyle()

Return type

str

textFormat(self) → QgsTextFormat

Returns the text format used for drawing text in the scalebar.

See also

setTextFormat()

New in version 3.2.

Return type

QgsTextFormat

timerEvent()
topLeftToReferencePoint()
type(self) → int
Return type

int

unitLabel(self) → str

Returns the label for units.

See also

setUnitLabel()

Return type

str

units(self) → QgsUnitTypes.DistanceUnit

Returns the distance units used by the scalebar.

See also

setUnits()

Return type

QgsUnitTypes.DistanceUnit

unitsPerSegment(self) → float

Returns the number of scalebar units per segment.

Return type

float

update(self)

Adjusts the scale bar box size and updates the item.

updateMicroFocus()
wheelEvent()
writeObjectPropertiesToElement()
writePropertiesToElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) → bool
Parameters
Return type

bool