Subgroup: Editor

Class: QgsEditorWidgetWrapper

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

Bases: qgis._gui.QgsWidgetWrapper

Create a new widget wrapper

Parameters:
  • vl – The layer on which the field is
  • fieldIdx – The field which will be controlled
  • editor – An editor widget. Can be NULL if one should be autogenerated.
  • parent – 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.

Methods

childEvent
connectNotify
constraintFailureReason Returns the reason why a constraint check has failed (or an empty string if constraint check was successful).
constraintResult Getter of constraintResult It’s the current result of the constraint on the widget influencing it’s visualization.
constraintResultVisible Getter of constraintResultVisible Defines if the constraint result should be visualized on the widget (with color).
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.
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 Get the current constraint status.
receivers
sender
senderSignalIndex
setConstraintResultVisible Setter of constraintResultVisible Defines if the constraint result should be visualized on the widget (with color).
setEnabled Is used to enable or disable the edit functionality of the managed widget.
setFeature Will be called when the feature changes
setHint Add a hint text on the widget
setValue Is called, when the value of the widget 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.

Attributes

ConstraintResultFailHard
ConstraintResultFailSoft
ConstraintResultPass
class ConstraintResult

Bases: int

ConstraintResultFailHard = 1
ConstraintResultFailSoft = 2
ConstraintResultPass = 0
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.

constraintResult(self) → QgsEditorWidgetWrapper.ConstraintResult

Getter of constraintResult It’s the current result of the constraint on the widget influencing it’s visualization.

New in version 3.0.

constraintResultVisible(self) → bool

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

New in version 3.0.

constraintResultVisibleChanged

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

constraintStatusChanged
Emit this signal when the constraint status changed.
constraintStatusChanged
Parameters:
  • constraint – represented as a string
  • desc – is the constraint description
  • err – the error represented as a string. Empty if none.
  • status – [signal]
createWidget()
customEvent()
defaultValue(self) → Any

Access the default value of the field.

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.

Returns:The field you are working on

See also

layer()

fieldIdx(self) → int

Access the field index.

Returns:The index of the field you are working on

See also

layer()

fromWidget(widget: QWidget) → QgsEditorWidgetWrapper

Will return a wrapper for a given widget

Parameters:widget – The widget which was created by a wrapper
Returns:The wrapper for the widget or NULL
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.

isInTable(parent: QWidget) → bool

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

Parameters:parent – the widget to check
Returns:true if yes
isSignalConnected()
isValidConstraint(self) → bool

Get the current constraint status.

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)

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

Parameters:constraintResultVisible – 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 – Enable or Disable?
setFeature(self, feature: QgsFeature)

Will be called when the feature changes

Is forwarded to the slot setValue()

Parameters:feature – The new feature
setHint(self, hintText: str)

Add a hint text on the widget

Parameters:hintText – 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. Update the widget representation to reflect the new value.

Parameters:value – The new value of the attribute
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 – 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 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.

Returns:The current value the widget represents
valueChanged

Emit this signal, whenever the value changed.

Parameters:value – The new value [signal]