Class: QgsUnitSelectionWidget

class qgis.gui.QgsUnitSelectionWidget

Bases: PyQt5.QtWidgets.QWidget

A widget displaying a combobox allowing the user to choose between various display units, such as millimeters or map unit. If the user chooses map units, a button appears allowing adjustment of minimum and maximum scaling.

QgsUnitSelectionWidget(parent: QWidget = None) Constructor for QgsUnitSelectionWidget.

Parameters

parent

parent widget

Methods

actionEvent

changeEvent

childEvent

closeEvent

connectNotify

contextMenuEvent

create

customEvent

destroy

disconnectNotify

dragEnterEvent

dragLeaveEvent

dragMoveEvent

dropEvent

enterEvent

event

focusInEvent

focusNextChild

focusNextPrevChild

focusOutEvent

focusPreviousChild

getMapUnitScale

Returns the map unit scale

getUnit

Gets the selected unit index

hideEvent

initPainter

inputMethodEvent

isSignalConnected

keyPressEvent

keyReleaseEvent

leaveEvent

metric

mouseDoubleClickEvent

mouseMoveEvent

mousePressEvent

mouseReleaseEvent

moveEvent

nativeEvent

paintEvent

receivers

resizeEvent

sender

senderSignalIndex

setMapCanvas

Sets the map canvas associated with the widget.

setMapUnitScale

Sets the map unit scale

setShowMapScaleButton

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

setUnit

Sets the selected unit

setUnitIndex

Sets the selected unit index

setUnits

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

sharedPainter

showEvent

showMapScaleButton

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

tabletEvent

timerEvent

unit

Returns the current predefined selected unit (if applicable).

updateMicroFocus

wheelEvent

Signals

changed

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

actionEvent(self, QActionEvent)
changeEvent(self, QEvent)
changed

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.

Parameters
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type

PYQT_SIGNAL

childEvent(self, QChildEvent)
closeEvent(self, QCloseEvent)
connectNotify(self, QMetaMethod)
contextMenuEvent(self, QContextMenuEvent)
create(self, window: PyQt5.sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)
customEvent(self, QEvent)
destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)
disconnectNotify(self, QMetaMethod)
dragEnterEvent(self, QDragEnterEvent)
dragLeaveEvent(self, QDragLeaveEvent)
dragMoveEvent(self, QDragMoveEvent)
dropEvent(self, QDropEvent)
enterEvent(self, QEvent)
event(self, QEvent) bool
focusInEvent(self, QFocusEvent)
focusNextChild(self) bool
focusNextPrevChild(self, bool) bool
focusOutEvent(self, QFocusEvent)
focusPreviousChild(self) bool
getMapUnitScale(self) QgsMapUnitScale

Returns the map unit scale

Return type

QgsMapUnitScale

getUnit(self) int

Gets the selected unit index

Return type

int

hideEvent(self, QHideEvent)
initPainter(self, QPainter)
inputMethodEvent(self, QInputMethodEvent)
isSignalConnected(self, QMetaMethod) bool
keyPressEvent(self, QKeyEvent)
keyReleaseEvent(self, QKeyEvent)
leaveEvent(self, QEvent)
metric(self, QPaintDevice.PaintDeviceMetric) int
mouseDoubleClickEvent(self, QMouseEvent)
mouseMoveEvent(self, QMouseEvent)
mousePressEvent(self, QMouseEvent)
mouseReleaseEvent(self, QMouseEvent)
moveEvent(self, QMoveEvent)
nativeEvent(self, Union[QByteArray, bytes, bytearray], PyQt5.sip.voidptr) Tuple[bool, int]
paintEvent(self, QPaintEvent)
receivers(self, PYQT_SIGNAL) int
resizeEvent(self, QResizeEvent)
sender(self) QObject
senderSignalIndex(self) int
setMapCanvas(self, canvas: QgsMapCanvas)

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

Parameters

canvas (QgsMapCanvas) – map canvas

New in version 2.12.

setMapUnitScale(self, scale: QgsMapUnitScale)

Sets the map unit scale

Parameters

scale (QgsMapUnitScale) –

setShowMapScaleButton(self, show: bool)

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

New in version 3.22.

Parameters

show (bool) –

setUnit(self, unit: QgsUnitTypes.RenderUnit)

Sets the selected unit

Parameters

unit (QgsUnitTypes.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

Note

available in Python bindings as setUnitIndex

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

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

Parameters
  • units (Iterable[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[QgsUnitTypes.RenderUnit]) Sets the units which the user can choose from in the combobox. Clears any existing units.

Parameters

units – list of valid units

New in version 2.9.

sharedPainter(self) QPainter
showEvent(self, QShowEvent)
showMapScaleButton(self) bool

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

New in version 3.22.

Return type

bool

tabletEvent(self, QTabletEvent)
timerEvent(self, QTimerEvent)
unit(self) QgsUnitTypes.RenderUnit

Returns the current predefined selected unit (if applicable).

Return type

QgsUnitTypes.RenderUnit

Returns

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

New in version 2.9.

updateMicroFocus(self)
wheelEvent(self, QWheelEvent)