Class: QgsAbstractProcessingParameterWidgetWrapper

A widget wrapper for Processing parameter value widgets.

Widget wrappers are used to create widgets for individual Processing parameters, and handle retrieving and setting the current value for those parameters.

Widget wrappers can be created for different dialog types, allowing different appearance and behavior of widgets depending on whether they are being created for use in a standard algorithm dialog, a batch processing dialog, or a modeler dialog.

Individual widget wrappers are not usually created directly, instead they are constructed through the central registry, via calls to QgsGui.processingGuiRegistry()->:py:func:createParameterWidgetWrapper() <qgis.gui.QgsAbstractProcessingParameterWidgetWrapper.createParameterWidgetWrapper>.

Added in version 3.4.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: createWidget(), setWidgetValue(), widgetValue()

Class Hierarchy

Inheritance diagram of qgis.gui.QgsAbstractProcessingParameterWidgetWrapper

Base classes

QObject

QgsExpressionContextGenerator

Abstract interface for generating an expression context.

Subclasses

QgsProcessingHiddenWidgetWrapper

A widget wrapper for hidden widgets.

Abstract Methods

createWidget

Creates a new widget which allows customization of the parameter's value.

setWidgetValue

Sets the current value for the parameter to show in the widget.

widgetValue

Returns the current value of the parameter.

Methods

createWrappedLabel

Creates and returns a new label to accompany widgets created by the wrapper.

createWrappedWidget

Creates and return a new wrapped widget which allows customization of the parameter's value.

linkedVectorLayer

Returns the optional vector layer associated with this widget wrapper, or None if no vector layer is applicable.

parameterDefinition

Returns the parameter definition associated with this wrapper.

parameterValue

Returns the current value of the parameter.

registerProcessingParametersGenerator

Registers a Processing parameters generator class that will be used to retrieve algorithm parameters for the wrapper when required (e.g. when a wrapper needs access to other parameter's values).

setParameterValue

Sets the current value for the parameter.

type

Returns the dialog type for which widgets and labels will be created by this wrapper.

widgetContext

Returns the context in which the Processing parameter widget is shown, e.g., the parent model algorithm, a linked map canvas, and other relevant information which allows the widget to fine-tune its behavior.

wrappedLabel

Returns the current wrapped label, if any.

wrappedWidget

Returns the current wrapped widget, if any.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsAbstractProcessingParameterWidgetWrapper. See the FAQ for more details.

createLabel

Creates a new label to accompany widgets created by the wrapper.

customProperties

Returns any custom properties set by the wrapper.

postInitialize

Called after all wrappers have been created within a particular dialog or context, allowing the wrapper to connect to the wrappers of other, related parameters.

registerProcessingContextGenerator

Registers a Processing context generator class that will be used to retrieve a Processing context for the wrapper when required.

setDialog

Sets the parent dialog in which the wrapper is shown.

setWidgetContext

Sets the context in which the Processing parameter widget is shown, e.g., the parent model algorithm, a linked map canvas, and other relevant information which allows the widget to fine-tune its behavior.

stretch

Returns the Qt layout "stretch" factor to use when adding this widget to a layout.

Signals

widgetValueHasChanged

Emitted whenever the parameter value (as defined by the wrapped widget) is changed.

class qgis.gui.QgsAbstractProcessingParameterWidgetWrapper[source]

Bases: QObject, QgsExpressionContextGenerator

__init__(parameter: QgsProcessingParameterDefinition | None = None, type: Qgis.ProcessingMode = Qgis.ProcessingMode.Standard, parent: QObject | None = None)

Constructor for QgsAbstractProcessingParameterWidgetWrapper, for the specified parameter definition and dialog type.

Parameters:
virtual createLabel(self) QLabel | None[source]

Creates a new label to accompany widgets created by the wrapper.

The caller takes ownership of the returned label. Some parameter type and dialog type combinations will return None for this method. If None is returned, then no label should be shown for the parameter’s widget (i.e. the label is embedded inside the widget itself).

See also

createWidget()

Return type:

Optional[QLabel]

abstract createWidget(self) QWidget | None[source]

Creates a new widget which allows customization of the parameter’s value.

The caller takes ownership of the returned widget.

See also

createLabel()

Return type:

Optional[QWidget]

createWrappedLabel(self) QLabel | None[source]

Creates and returns a new label to accompany widgets created by the wrapper.

The caller takes ownership of the returned label. Some parameter type and dialog type combinations will return None for this method. If None is returned, then no label should be shown for the parameter’s widget (i.e. the label is embedded inside the widget itself).

The wrapped label can be retrieved at a later stage by calling wrappedLabel().

Return type:

Optional[QLabel]

createWrappedWidget(self, context: QgsProcessingContext) QWidget | None[source]

Creates and return a new wrapped widget which allows customization of the parameter’s value.

The caller takes ownership of the returned widget. The wrapped widget can be retrieved at a later stage by calling wrappedWidget().

The supplied context is used while initializing the widget to the parameter’s default value.

Parameters:

context (QgsProcessingContext)

Return type:

Optional[QWidget]

virtual customProperties(self) Dict[str, Any][source]

Returns any custom properties set by the wrapper.

Return type:

Dict[str, Any]

linkedVectorLayer(self) QgsVectorLayer | None[source]

Returns the optional vector layer associated with this widget wrapper, or None if no vector layer is applicable.

This is used to correctly generate expression contexts within the GUI, e.g. to allow expression buttons and property override buttons to correctly show the appropriate vector layer fields.

Added in version 3.6.

Return type:

Optional[QgsVectorLayer]

property param

Returns the parameter definition associated with this wrapper.

Return type:

Optional[QgsProcessingParameterDefinition]

parameterDefinition(self) QgsProcessingParameterDefinition | None[source]

Returns the parameter definition associated with this wrapper.

Return type:

Optional[QgsProcessingParameterDefinition]

parameterValue(self) Any[source]

Returns the current value of the parameter.

Return type:

Any

virtual postInitialize(self, wrappers: Iterable[QgsAbstractProcessingParameterWidgetWrapper])[source]

Called after all wrappers have been created within a particular dialog or context, allowing the wrapper to connect to the wrappers of other, related parameters.

Parameters:

wrappers (Iterable[QgsAbstractProcessingParameterWidgetWrapper])

virtual registerProcessingContextGenerator(self, generator: QgsProcessingContextGenerator | None)[source]

Registers a Processing context generator class that will be used to retrieve a Processing context for the wrapper when required.

Care must be taken to call the base class implementation if overwrite this method.

Parameters:

generator (Optional[QgsProcessingContextGenerator])

registerProcessingParametersGenerator(self, generator: QgsProcessingParametersGenerator | None)[source]

Registers a Processing parameters generator class that will be used to retrieve algorithm parameters for the wrapper when required (e.g. when a wrapper needs access to other parameter’s values).

Added in version 3.14.

Parameters:

generator (Optional[QgsProcessingParametersGenerator])

virtual setDialog(self, dialog: QDialog | None)[source]

Sets the parent dialog in which the wrapper is shown.

Added in version 3.8.

Parameters:

dialog (Optional[QDialog])

setParameterValue(self, value: Any, context: QgsProcessingContext)[source]

Sets the current value for the parameter.

The context argument is used to specify the wider Processing context which the current value is associated with.

See also

parameterValue()

Parameters:
virtual setWidgetContext(self, context: QgsProcessingParameterWidgetContext)[source]

Sets the context in which the Processing parameter widget is shown, e.g., the parent model algorithm, a linked map canvas, and other relevant information which allows the widget to fine-tune its behavior.

Subclasses should take care to call the base class method when reimplementing this method.

See also

widgetContext()

Parameters:

context (QgsProcessingParameterWidgetContext)

abstract setWidgetValue(self, value: Any, context: QgsProcessingContext)[source]

Sets the current value for the parameter to show in the widget.

The context argument is used to specify the wider Processing context which the current value is associated with.

See also

widgetValue()

Parameters:
virtual stretch(self) int[source]

Returns the Qt layout “stretch” factor to use when adding this widget to a layout.

The default implementation returns 0.

Added in version 3.14.

Return type:

int

type(self) Qgis.ProcessingMode[source]

Returns the dialog type for which widgets and labels will be created by this wrapper.

Return type:

Qgis.ProcessingMode

widgetContext(self) QgsProcessingParameterWidgetContext

Returns the context in which the Processing parameter widget is shown, e.g., the parent model algorithm, a linked map canvas, and other relevant information which allows the widget to fine-tune its behavior.

Return type:

QgsProcessingParameterWidgetContext

abstract widgetValue(self) Any[source]

Returns the current value of the parameter.

See also

setWidgetValue()

Return type:

Any

signal widgetValueHasChanged(wrapper: QgsAbstractProcessingParameterWidgetWrapper)[source]

Emitted whenever the parameter value (as defined by the wrapped widget) is changed.

Parameters:

wrapper (QgsAbstractProcessingParameterWidgetWrapper)

wrappedLabel(self) QLabel | None[source]

Returns the current wrapped label, if any.

Return type:

Optional[QLabel]

wrappedWidget(self) QWidget | None[source]

Returns the current wrapped widget, if any.

Return type:

Optional[QWidget]