Class: QgsAttributeForm

Class Hierarchy

Inheritance diagram of qgis.gui.QgsAttributeForm

Base classes

QWidget

QObject

QPaintDevice

Methods

addInterface

Takes ownership

aggregateFilter

The aggregate filter is only useful if the form is in AggregateFilter mode.

changeAttribute

Call this to change the content of a given attribute.

changeGeometry

Changes the geometry of the feature attached to the form.

currentFormFeature

Returns the feature that is currently displayed in the form with all the changes received on editing the values in the widgets.

disconnectButtonBox

Disconnects the button box (OK/Cancel) from the accept/resetValues slots If this method is called, you have to create these connections from outside

displayWarning

Displays a warning message in the form message bar

editable

Returns if the form is currently in editable mode.

eventFilter

Intercepts keypress on custom form (escape should not close it)

feature

hideButtonBox

Hides the button box (OK/Cancel) and enables auto-commit

layer

Returns the layer for which this form is shown

mode

Returns the current mode of the form.

needsGeometry

Returns True if any of the form widgets need feature geometry

parentFormValueChanged

Is called in embedded forms when an attribute value in the parent form has changed to newValue.

refreshFeature

reload current feature

resetSearch

Resets the search/filter form values.

resetValues

Sets all values to the values of the current feature

save

Save all the values from the editors to the layer.

saveWithDetails

Save all the values from the editors to the layer.

setEditCommandMessage

Sets the edit command message (Undo) that will be used when the dialog is accepted

setExtraContextScope

Sets an additional expression context scope to be used for calculations in this form.

setFeature

Update all editors to correspond to a different feature.

setMessageBar

Sets the message bar to display feedback from the form in.

setMode

Sets the current mode of the form.

setMultiEditFeatureIds

Sets all feature IDs which are to be edited if the form is in multiedit mode

showButtonBox

Shows the button box (OK/Cancel) and disables auto-commit

Signals

attributeChanged

Notifies about changes of attributes, this signal is not emitted when the value is set back to the original one.

closed

Emitted when the user selects the close option from the form's button bar.

featureSaved

Emitted when a feature is changed or added

filterExpressionSet

Emitted when a filter expression is set using the form.

flashFeatures

Emitted when the user chooses to flash a filtered set of features.

modeChanged

Emitted when the form changes mode.

openFilteredFeaturesAttributeTable

Emitted when the user chooses to open the attribute table dialog with a filtered set of features.

widgetValueChanged

Notifies about changes of attributes

zoomToFeatures

Emitted when the user chooses to zoom to a filtered set of features.

Attributes

AddFeatureMode

AggregateSearchMode

FilterAnd

FilterOr

IdentifyMode

MultiEditMode

ReplaceFilter

SearchMode

SingleEditMode

class qgis.gui.QgsAttributeForm(vl: QgsVectorLayer | None, feature: QgsFeature = QgsFeature(), context: QgsAttributeEditorContext = QgsAttributeEditorContext(), parent: QWidget | None = None)[source]

Bases: QWidget

AddFeatureMode = 1
AggregateSearchMode = 4
FilterAnd = 1
FilterOr = 2
class FilterType

Bases: int

IdentifyMode = 5
class Mode

Bases: int

MultiEditMode = 2
ReplaceFilter = 0
SearchMode = 3
SingleEditMode = 0
addInterface(self, iface: QgsAttributeFormInterface | None)[source]

Takes ownership

Parameters:

iface (Optional[QgsAttributeFormInterface])

aggregateFilter(self) str[source]

The aggregate filter is only useful if the form is in AggregateFilter mode. In this case it will return a combined expression according to the chosen filters on all attribute widgets.

Return type:

str

signal attributeChanged[source]

Notifies about changes of attributes, this signal is not emitted when the value is set back to the original one.

Parameters:
  • attribute – The name of the attribute that changed.

  • value – The new value of the attribute.

Deprecated since version 3.0.

changeAttribute(self, field: str | None, value: Any, hintText: str | None = '')[source]

Call this to change the content of a given attribute. Will update the

Parameters:
  • field (Optional[str])

  • value (Any)

  • hintText (Optional[str] = '')

QgsAttributeForm.changeAttribute(s) related to this field.

changeAttribute(s) related to this field.

Parameters:
  • field (Optional[str]) – The field to change

  • value (Any) – The new value

  • hintText (Optional[str] = '') – A hint text for non existent joined features

changeGeometry(self, geometry: QgsGeometry)[source]

Changes the geometry of the feature attached to the form.

Added in version 3.30.

Parameters:

geometry (QgsGeometry)

signal closed[source]

Emitted when the user selects the close option from the form’s button bar.

currentFormFeature(self) QgsFeature[source]

Returns the feature that is currently displayed in the form with all the changes received on editing the values in the widgets.

Added in version 3.16.

Return type:

QgsFeature

disconnectButtonBox(self)[source]

Disconnects the button box (OK/Cancel) from the accept/resetValues slots If this method is called, you have to create these connections from outside

displayWarning(self, message: str | None)[source]

Displays a warning message in the form message bar

Parameters:

message (Optional[str]) – message string

See also

mode()

Added in version 3.12.

editable(self) bool[source]

Returns if the form is currently in editable mode.

Return type:

bool

Returns:

Editable mode of this form

eventFilter(self, object: QObject | None, event: QEvent | None) bool[source]

Intercepts keypress on custom form (escape should not close it)

Parameters:
  • object (Optional[QObject]) – The object for which the event has been sent

  • event (Optional[QEvent]) – The event which is being filtered

Return type:

bool

Returns:

True if the event has been handled (key was ESC)

feature(self) QgsFeature
Return type:

QgsFeature

signal featureSaved(feature: QgsFeature)[source]

Emitted when a feature is changed or added

Parameters:

feature (QgsFeature)

signal filterExpressionSet(expression: str, type: QgsAttributeForm.FilterType)[source]

Emitted when a filter expression is set using the form.

Parameters:
signal flashFeatures(filter: str)[source]

Emitted when the user chooses to flash a filtered set of features.

Parameters:

filter (str)

hideButtonBox(self)[source]

Hides the button box (OK/Cancel) and enables auto-commit

Note

set Embed in QgsAttributeEditorContext in constructor instead

layer(self) QgsVectorLayer | None[source]

Returns the layer for which this form is shown

Return type:

Optional[QgsVectorLayer]

Returns:

Layer

mode(self) QgsAttributeEditorContext.Mode[source]

Returns the current mode of the form.

See also

setMode()

Return type:

QgsAttributeEditorContext.Mode

signal modeChanged(mode: QgsAttributeEditorContext.Mode)[source]

Emitted when the form changes mode.

Parameters:

mode (QgsAttributeEditorContext.Mode) – new mode

needsGeometry(self) bool[source]

Returns True if any of the form widgets need feature geometry

Added in version 3.20.

Return type:

bool

signal openFilteredFeaturesAttributeTable(filter: str)[source]

Emitted when the user chooses to open the attribute table dialog with a filtered set of features.

Added in version 3.24.

Parameters:

filter (str)

parentFormValueChanged(self, attribute: str | None, newValue: Any)[source]

Is called in embedded forms when an attribute value in the parent form has changed to newValue.

Notify the form widgets that something has changed in case they have filter expressions that depend on the parent form scope.

Added in version 3.14.

Parameters:
  • attribute (Optional[str])

  • newValue (Any)

refreshFeature(self)[source]

reload current feature

resetSearch(self)[source]

Resets the search/filter form values.

resetValues(self)[source]

Sets all values to the values of the current feature

save(self) bool[source]

Save all the values from the editors to the layer.

Return type:

bool

Returns:

True if successful

saveWithDetails(self)[source]

Save all the values from the editors to the layer.

Returns:

  • True if save was successful

  • error: an explanatory error message if an error occurs while saving the form.

Added in version 3.18.

setEditCommandMessage(self, message: str | None)[source]

Sets the edit command message (Undo) that will be used when the dialog is accepted

Parameters:

message (Optional[str]) – The message

setExtraContextScope(self, extraScope: QgsExpressionContextScope | None)[source]

Sets an additional expression context scope to be used for calculations in this form.

Added in version 3.16.

Parameters:

extraScope (Optional[QgsExpressionContextScope])

setFeature(self, feature: QgsFeature)[source]

Update all editors to correspond to a different feature.

Parameters:

feature (QgsFeature) – The feature which will be represented by the form

setMessageBar(self, messageBar: QgsMessageBar | None)[source]

Sets the message bar to display feedback from the form in. This is used in the search/filter mode to display the count of selected features.

Parameters:

messageBar (Optional[QgsMessageBar]) – target message bar

setMode(self, mode: QgsAttributeEditorContext.Mode)[source]

Sets the current mode of the form.

Parameters:

mode (QgsAttributeEditorContext.Mode) – form mode

See also

mode()

setMultiEditFeatureIds(self, fids: Any)[source]

Sets all feature IDs which are to be edited if the form is in multiedit mode

Parameters:

fids (Any) – feature ID list

showButtonBox(self)[source]

Shows the button box (OK/Cancel) and disables auto-commit

Note

set Embed in QgsAttributeEditorContext in constructor instead

signal widgetValueChanged(attribute: str, value: object, attributeChanged: bool)[source]

Notifies about changes of attributes

Parameters:
  • attribute (str) – The name of the attribute that changed.

  • value (object) – The new value of the attribute.

  • attributeChanged (bool) – If True, it corresponds to an actual change of the feature attribute

signal zoomToFeatures(filter: str)[source]

Emitted when the user chooses to zoom to a filtered set of features.

Parameters:

filter (str)