Class: QgsExtentWidget

A widget for configuration of a map extent.

Besides allowing the user to enter the extent manually, it comes with options to use original extent or extent defined by the current view in map canvas.

When using the widget, make sure to call setOriginalExtent(), setCurrentExtent() and setOutputCrs() during initialization.

Added in version 3.14.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsExtentWidget

Base classes

QWidget

QObject

QPaintDevice

Methods

clear

Clears the widget, setting it to a null value.

currentCrs

Returns the coordinate reference system for the current extent set for the widget.

currentExtent

Returns the current extent set for the widget.

extentLayerName

Returns the name of the extent layer.

extentState

Returns the currently selected state for the widget's extent.

isValid

Returns True if the widget is in a valid state, i.e. has an extent set.

originalCrs

Returns the original coordinate reference system set for the widget.

originalExtent

Returns the original extent set for the widget.

outputCrs

Returns the current output CRS, used in the display.

outputExtent

Returns the extent shown in the widget - in output CRS coordinates.

ratio

Returns the current fixed aspect ratio to be used when dragging extent onto the canvas.

setCurrentExtent

Sets the current extent to show in the widget - should be called as part of initialization (or whenever current extent changes).

setMapCanvas

Sets the map canvas to enable dragging of extent on a canvas.

setNullValueAllowed

Sets whether the widget can be set to a "not set" (null) state.

setOriginalExtent

Sets the original extent and coordinate reference system for the widget.

setOutputCrs

Sets the output CRS - may need to be used for transformation from original/current extent.

setOutputExtentFromCurrent

Sets the output extent to be the same as current extent (may be transformed to output CRS).

setOutputExtentFromDrawOnCanvas

Sets the output extent by dragging on the canvas.

setOutputExtentFromLayer

Sets the output extent to match a layer's extent (may be transformed to output CRS).

setOutputExtentFromOriginal

Sets the output extent to be the same as original extent (may be transformed to output CRS).

setOutputExtentFromUser

Sets the output extent to a custom extent (may be transformed to output CRS).

setRatio

Sets a fixed aspect ratio to be used when dragging extent onto the canvas.

Signals

extentChanged

Emitted when the widget's extent is changed.

extentLayerChanged

Emitted when the extent layer is changed.

toggleDialogVisibility

Emitted when the parent dialog visibility must be changed (e.g. to permit access to the map canvas).

validationChanged

Emitted when the widget's validation state changes.

Attributes

CondensedStyle

CurrentExtent

DrawOnCanvas

ExpandedStyle

OriginalExtent

ProjectLayerExtent

UserExtent

class qgis.gui.QgsExtentWidget[source]

Bases: QWidget

__init__(parent: QWidget | None = None, style: QgsExtentWidget.WidgetStyle = QgsExtentWidget.CondensedStyle)

Constructor for QgsExtentWidget.

Parameters:
  • parent (Optional[QWidget] = None)

  • style (QgsExtentWidget.WidgetStyle = QgsExtentWidget.CondensedStyle)

CondensedStyle = 0
CurrentExtent = 1
DrawOnCanvas = 4
ExpandedStyle = 1
class ExtentState

Bases: int

OriginalExtent = 0
ProjectLayerExtent = 3
UserExtent = 2
class WidgetStyle

Bases: int

clear(self)[source]

Clears the widget, setting it to a null value.

currentCrs(self) QgsCoordinateReferenceSystem[source]

Returns the coordinate reference system for the current extent set for the widget. The current extent and CRS usually reflects the map canvas extent and CRS.

See also

currentExtent()

Return type:

QgsCoordinateReferenceSystem

currentExtent(self) QgsRectangle[source]

Returns the current extent set for the widget. The current extent is usually set to match the current map canvas extent.

See also

currentCrs()

Return type:

QgsRectangle

signal extentChanged(r: QgsRectangle)[source]

Emitted when the widget’s extent is changed.

Parameters:

r (QgsRectangle)

signal extentLayerChanged(layer: QgsMapLayer)[source]

Emitted when the extent layer is changed.

Added in version 3.44.

Parameters:

layer (QgsMapLayer)

extentLayerName(self) str[source]

Returns the name of the extent layer.

Return type:

str

extentState(self) QgsExtentWidget.ExtentState[source]

Returns the currently selected state for the widget’s extent.

Return type:

QgsExtentWidget.ExtentState

isValid(self) bool[source]

Returns True if the widget is in a valid state, i.e. has an extent set.

Return type:

bool

originalCrs(self) QgsCoordinateReferenceSystem[source]

Returns the original coordinate reference system set for the widget.

See also

originalExtent()

Return type:

QgsCoordinateReferenceSystem

originalExtent(self) QgsRectangle[source]

Returns the original extent set for the widget.

See also

originalCrs()

Return type:

QgsRectangle

outputCrs(self) QgsCoordinateReferenceSystem[source]

Returns the current output CRS, used in the display.

See also

outputExtent()

Return type:

QgsCoordinateReferenceSystem

outputExtent(self) QgsRectangle[source]

Returns the extent shown in the widget - in output CRS coordinates.

See also

outputCrs()

Return type:

QgsRectangle

ratio(self) QSize[source]

Returns the current fixed aspect ratio to be used when dragging extent onto the canvas. If the aspect ratio isn’t fixed, the width and height will be set to zero.

Return type:

QSize

setCurrentExtent(self, currentExtent: QgsRectangle, currentCrs: QgsCoordinateReferenceSystem)[source]

Sets the current extent to show in the widget - should be called as part of initialization (or whenever current extent changes). The current extent is usually set to match the current map canvas extent.

See also

currentExtent()

See also

currentCrs()

Parameters:
setMapCanvas(self, canvas: QgsMapCanvas | None, drawOnCanvasOption: bool = True)[source]

Sets the map canvas to enable dragging of extent on a canvas.

Parameters:
  • canvas (Optional[QgsMapCanvas]) – the map canvas

  • drawOnCanvasOption (bool = True) – set to false to disable to draw on canvas option

setNullValueAllowed(self, allowed: bool, notSetText: str | None = '')[source]

Sets whether the widget can be set to a “not set” (null) state.

The specified notSetText will be used for showing null values.

Note

This mode only applies to widgets in the condensed state!

Parameters:
  • allowed (bool)

  • notSetText (Optional[str] = '')

setOriginalExtent(self, originalExtent: QgsRectangle, originalCrs: QgsCoordinateReferenceSystem)[source]

Sets the original extent and coordinate reference system for the widget. This should be called as part of initialization.

See also

originalExtent()

See also

originalCrs()

Parameters:
setOutputCrs(self, outputCrs: QgsCoordinateReferenceSystem)[source]

Sets the output CRS - may need to be used for transformation from original/current extent. Should be called as part of initialization and whenever the the output CRS is changed. The current extent will be reprojected into the new output CRS.

Parameters:

outputCrs (QgsCoordinateReferenceSystem)

setOutputExtentFromCurrent(self)[source]

Sets the output extent to be the same as current extent (may be transformed to output CRS).

setOutputExtentFromDrawOnCanvas(self)[source]

Sets the output extent by dragging on the canvas.

setOutputExtentFromLayer(self, layer: QgsMapLayer | None)[source]

Sets the output extent to match a layer’s extent (may be transformed to output CRS).

Parameters:

layer (Optional[QgsMapLayer])

setOutputExtentFromOriginal(self)[source]

Sets the output extent to be the same as original extent (may be transformed to output CRS).

setOutputExtentFromUser(self, extent: QgsRectangle, crs: QgsCoordinateReferenceSystem)[source]

Sets the output extent to a custom extent (may be transformed to output CRS).

Parameters:
setRatio(self, ratio: QSize)[source]

Sets a fixed aspect ratio to be used when dragging extent onto the canvas. To unset a fixed aspect ratio, set the width and height to zero.

Parameters:

ratio (QSize) – aspect ratio’s width and height

signal toggleDialogVisibility(visible: bool)[source]

Emitted when the parent dialog visibility must be changed (e.g. to permit access to the map canvas)

Parameters:

visible (bool)

signal validationChanged(valid: bool)[source]

Emitted when the widget’s validation state changes.

Parameters:

valid (bool)