Class: QgsEditorWidgetWrapper

class qgis.gui.QgsEditorWidgetWrapper

Bases: QgsWidgetWrapper

Manages an editor widget Widget and wrapper share the same parent

A wrapper controls one attribute editor widget and is able to create a default widget or use a pre-existent widget. It is able to set the widget to the value implied by a field of a vector layer, or return the value it currently holds. Every time it is changed it has to emit a valueChanged signal. If it fails to do so, there is no guarantee that the changed status of the widget will be saved.

It can also handle additional fields of a vector layer and would set the widget for their corresponding values and emit valuesChanged signal.

QgsEditorWidgetWrapper(vl: QgsVectorLayer, fieldIdx: int, editor: QWidget = None, parent: QWidget = None) Create a new widget wrapper

Parameters
class ConstraintResult

Bases: int

ConstraintResultFailHard = 1
ConstraintResultFailSoft = 2
ConstraintResultPass = 0
additionalFieldValues(self)List[Any]

Will be used to access the widget’s values for potential additional fields handled by the widget

Return type

List[Any]

Returns

A map of additional field names with their corresponding values

New in version 3.10.

additionalFields(self)List[str]

Returns the list of additional fields which the editor handles

New in version 3.10.

Return type

List[str]

childEvent(self, QChildEvent)
connectNotify(self, QMetaMethod)
constraintFailureReason(self)str

Returns the reason why a constraint check has failed (or an empty string if constraint check was successful).

New in version 3.0.

Return type

str

constraintResult(self)QgsEditorWidgetWrapper.ConstraintResult

Returns the constraint result, which is the current result of the constraint on the widget influencing its visualization.

New in version 3.0.

Return type

QgsEditorWidgetWrapper.ConstraintResult

constraintResultVisible(self)bool

Returns whether the constraint result is visible.

Returns True if the constraint result will be visualized on the widget (with color). This will be disabled when the form is not editable.

New in version 3.0.

Return type

bool

constraintResultVisibleChanged

Emit this signal when the constraint result visibility changed. [signal]

Parameters

visible (bool) –

constraintStatusChanged
Parameters
  • constraint (str) – represented as a string

  • desc (str) – is the constraint description

  • err (str) – the error represented as a string. Empty if none.

  • status (QgsEditorWidgetWrapper.ConstraintResult) – [signal]

createWidget(self, parent: QWidget)QWidget

This method should create a new widget with the provided parent. This will only be called if the form did not already provide a widget, so it is not guaranteed to be called! You should not do initialization stuff, which also has to be done for custom editor widgets inside this method. Things like filling comboboxes and assigning other data which will also be used to make widgets on forms created in the QtDesigner usable should be assigned in initWidget().

Parameters

parent – You should set this parent on the created widget.

Returns

A new widget

customEvent(self, QEvent)
defaultValue(self)Any

Access the default value of the field.

Return type

Any

Returns

the default value of the field

See also

layer()

disconnectNotify(self, QMetaMethod)
emitValueChanged(self)

Will call the value() method to determine the emitted value

field(self)QgsField

Access the field.

Return type

QgsField

Returns

The field you are working on

See also

layer()

fieldIdx(self)int

Access the field index.

Return type

int

Returns

The index of the field you are working on

See also

layer()

formFeature(self)QgsFeature

The feature currently being edited, in its current state

Return type

QgsFeature

Returns

the feature currently being edited, in its current state

New in version 3.2.

fromWidget(widget: QWidget)QgsEditorWidgetWrapper

Will return a wrapper for a given widget

Parameters

widget (QWidget) – The widget which was created by a wrapper

Return type

QgsEditorWidgetWrapper

Returns

The wrapper for the widget or None

initWidget(self, editor: QWidget)

This method should initialize the editor widget with runtime data. Fill your comboboxes here.

Parameters

editor – The widget which will represent this attribute editor in a form.

isBlockingCommit(self)bool

Returns True if the widget is preventing the feature from being committed. This may be True as a result of attribute values failing enforced field constraints.

New in version 3.0.

Return type

bool

isInTable(parent: QWidget)bool

Check if the given widget or one of its parent is a QTableView.

Parameters

parent (QWidget) – the widget to check

Return type

bool

Returns

True if yes

isSignalConnected(self, QMetaMethod)bool
isValidConstraint(self)bool

Gets the current constraint status.

Return type

bool

Returns

True if the constraint is valid or if there’s no constraint, False otherwise

New in version 2.16.

parentFormValueChanged(self, attribute: str, value: Any)

Is called in embedded form widgets when an attribute value in the parent form has changed.

The default implementations does nothing. Subclasses should reimplement this method to notify the form widgets that something has changed in case they have filter expressions that depend on the parent form scope.

New in version 3.14.

Parameters
  • attribute (str) –

  • value (Any) –

receivers(self, PYQT_SIGNAL)int
sender(self)QObject
senderSignalIndex(self)int
setConstraintResultVisible(self, constraintResultVisible: bool)

Sets whether the constraint result is visible.

Controls if the constraint result should be visualized on the widget (with color). This will be disabled when the form is not editable.

Parameters

constraintResultVisible (bool) – if constraintResult should be displayed (mostly editable status)

New in version 3.0.

setEnabled(self, enabled: bool)

Is used to enable or disable the edit functionality of the managed widget. By default this will enable or disable the whole widget

Parameters

enabled (bool) – Enable or Disable?

setFeature(self, feature: QgsFeature)

Will be called when the feature changes

Is forwarded to the slot setValues()

Parameters

feature (QgsFeature) – The new feature

setFormFeature(self, feature: QgsFeature)

Set the feature currently being edited to feature

New in version 3.2.

Parameters

feature (QgsFeature) –

setFormFeatureAttribute(self, attributeName: str, attributeValue: Any)bool

Update the feature currently being edited by changing its attribute attributeName to attributeValue

Return type

bool

Returns

bool True on success

New in version 3.2.

Parameters
  • attributeName (str) –

  • attributeValue (Any) –

setHint(self, hintText: str)

Add a hint text on the widget

Parameters

hintText (str) – The hint text to display

New in version 3.0.

setValue(self, value: Any)

Is called when the value of the widget needs to be changed. Updates the widget representation to reflect the new value.

Parameters

value (Any) – The new value of the attribute

Deprecated since version QGIS: 3.10

setValues(self, value: Any, additionalValues: Iterable[Any])

Is called when the value of the widget or additional field values needs to be changed. Updates the widget representation to reflect the new values.

New in version 3.10.

Parameters
  • value (Any) –

  • additionalValues (Iterable[Any]) –

showIndeterminateState(self)

Sets the widget to display in an indeterminate “mixed value” state.

New in version 2.16.

timerEvent(self, QTimerEvent)
updateConstraint(self, featureContext: QgsFeature, constraintOrigin: QgsFieldConstraints.ConstraintOrigin = QgsFieldConstraints.ConstraintOriginNotSet)

Update constraint.

Parameters
  • featureContext (QgsFeature) – the feature to use to evaluate the constraint

  • constraintOrigin (QgsFieldConstraints.ConstraintOrigin = QgsFieldConstraints.ConstraintOriginNotSet) – optional origin for constraints to check. This can be used to limit the constraints tested to only provider or layer based constraints.

New in version 2.16.

updateConstraint(self, layer: QgsVectorLayer, index: int, feature: QgsFeature, constraintOrigin: QgsFieldConstraints.ConstraintOrigin = QgsFieldConstraints.ConstraintOriginNotSet) Update constraint on a feature coming from a specific layer.

Parameters
  • layer – The vector layer where the feature is defined

  • index – The index of the field to check

  • feature – The feature to use to evaluate the constraint

  • constraintOrigin – Optional origin for constraints to check. This can be used to limit the constraints tested to only provider or layer based constraints.

New in version 3.0.

updateConstraintWidgetStatus(self)

This should update the widget with a visual cue if a constraint status changed.

By default a stylesheet will be applied on the widget that changes the background color to red.

This can be overwritten in subclasses to allow individual widgets to change the visual cue.

New in version 2.16.

value(self)Any

Will be used to access the widget’s value. Read the value from the widget and return it properly formatted to be saved in the attribute.

If an invalid variant is returned this will be interpreted as no change. Be sure to return a NULL QVariant if it should be set to NULL.

Return type

Any

Returns

The current value the widget represents

valueChanged

Emit this signal, whenever the value changed.

Parameters

value (Any) – The new value

Deprecated since version QGIS: 3.10 use valuesChanged signal instead [signal]

valuesChanged

Emit this signal, whenever the value changed. It will also return the values for the additional fields handled by the widget

Parameters
  • value (Any) – The new value

  • additionalFieldValues (Iterable[Any] = []) – A map of additional field names with their corresponding values

New in version 3.10: [signal]