Class: QgsUnitSelectionWidget

A widget displaying a combobox allowing the user to choose between various display units, such as millimeters or map units.

If the user chooses map units, a button appears allowing adjustment of minimum and maximum scaling.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsUnitSelectionWidget

Base classes

QWidget

QObject

QPaintDevice

class qgis.gui.QgsUnitSelectionWidget[source]

Bases: QWidget

__init__(parent: QWidget | None = None)

Constructor for QgsUnitSelectionWidget.

Parameters:

parent (Optional[QWidget] = None) – parent widget

signal changed[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

getMapUnitScale(self) QgsMapUnitScale[source]

Returns the map unit scale

Return type:

QgsMapUnitScale

getUnit(self) int[source]

Gets the selected unit index

Return type:

int

setMapCanvas(self, canvas: QgsMapCanvas | None)[source]

Sets the map canvas associated with the widget. This allows the widget to retrieve the current map scale from the canvas.

Parameters:

canvas (Optional[QgsMapCanvas]) – map canvas

setMapUnitScale(self, scale: QgsMapUnitScale)[source]

Sets the map unit scale

Parameters:

scale (QgsMapUnitScale)

setShowMapScaleButton(self, show: bool)[source]

Sets whether the widget can show the map scale button when the Map Units option is selected.

Added in version 3.22.

Parameters:

show (bool)

setUnit(self, unit: Qgis.RenderUnit)[source]

Sets the selected unit

Parameters:

unit (Qgis.RenderUnit) – predefined unit to set as current

setUnitIndex(self, unitIndex: int)

Sets the selected unit index

Parameters:

unitIndex (int) – index of unit to set as current

setUnits(self, units: Iterable[str | None], mapUnitIdx: int)[source]

Sets the units which the user can choose from in the combobox.

Parameters:
  • units (Iterable[Optional[str]]) – list of strings for custom units to display in the widget

  • mapUnitIdx (int) – specifies which entry corresponds to the map units, or -1 if none

setUnits(self, units: Iterable[Qgis.RenderUnit]) Sets the units which the user can choose from in the combobox. Clears any existing units.

Parameters:

units – list of valid units

showMapScaleButton(self) bool[source]

Returns True if the widget can show the map scale button when the Map Units option is selected.

Added in version 3.22.

Return type:

bool

unit(self) Qgis.RenderUnit[source]

Returns the current predefined selected unit (if applicable).

Return type:

Qgis.RenderUnit

Returns:

selected output unit, or QgsUnitTypes.RenderUnknownUnit if the widget was populated with custom unit types