Class: QgsEditorWidgetWrapper

class qgis.gui.QgsEditorWidgetWrapper(vl: QgsVectorLayer, fieldIdx: int, editor: QWidget = None, parent: QWidget = None)

Bases: QgsWidgetWrapper

Create a new widget wrapper

Parameters
  • vl (QgsVectorLayer) – The layer on which the field is

  • fieldIdx (int) – The field which will be controlled

  • editor (QWidget = None) – An editor widget. Can be None if one should be autogenerated.

  • parent (QWidget = None) – A parent widget for this widget wrapper and the created widget.

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.

Methods

additionalFieldValues

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

additionalFields

Returns the list of additional fields which the editor handles

childEvent

connectNotify

constraintFailureReason

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

constraintResult

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

constraintResultVisible

Returns whether the constraint result is visible.

createWidget

customEvent

defaultValue

Access the default value of the field.

disconnectNotify

emitValueChanged

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

field

Access the field.

fieldIdx

Access the field index.

formFeature

The feature currently being edited, in its current state

fromWidget

Will return a wrapper for a given widget

initWidget

isBlockingCommit

Returns true if the widget is preventing the feature from being committed.

isInTable

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

isSignalConnected

isValidConstraint

Gets the current constraint status.

receivers

sender

senderSignalIndex

setConstraintResultVisible

Sets whether the constraint result is visible.

setEnabled

Is used to enable or disable the edit functionality of the managed widget.

setFeature

Will be called when the feature changes

setFormFeature

Set the feature currently being edited to feature

setFormFeatureAttribute

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

setHint

Add a hint text on the widget

setValue

param value

setValues

Is called, when the value of the widget or additional field values needs to be changed.

showIndeterminateState

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

timerEvent

updateConstraint

Update constraint.

updateConstraintWidgetStatus

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

value

Will be used to access the widget’s value.

Signals

constraintResultVisibleChanged

Emit this signal when the constraint result visibility changed.

constraintStatusChanged

Emit this signal when the constraint status changed.

valueChanged

Emit this signal, whenever the value changed.

valuesChanged

Emit this signal, whenever the value changed.

Attributes

ConstraintResultFailHard

ConstraintResultFailSoft

ConstraintResultPass

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()
connectNotify()
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

Emit this signal when the constraint status changed. 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()
customEvent()
defaultValue(self) → Any

Access the default value of the field.

Return type

Any

Returns

the default value of the field

See also

layer()

disconnectNotify()
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()
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()
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.

receivers()
sender()
senderSignalIndex()
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)
Parameters

value (Any) –

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

Is called, when the value of the widget or additional field values needs to be changed. Update 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()
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]