Class: QgsAttributeForm

The attribute form widget for vector layer features.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsAttributeForm

Base classes

QWidget

QObject

QPaintDevice

class qgis.gui.QgsAttributeForm[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]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

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

Call this to change the content of a given attribute. Will update the editor(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]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

static createFeature(layer: QgsVectorLayer | None, geometry: QgsGeometry, attributes: Dict[int, Any], context: QgsExpressionContext) QgsFeature[source]

Creates a new feature for a given layer taking into account attribute form-specific context such as the remembrance and reuse of last attribute values.

Added in version 4.0.

Parameters:
Return type:

QgsFeature

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

virtual 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

Returns feature of attribute form.

Return type:

QgsFeature

signal featureSaved[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

signal filterExpressionSet[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

signal flashFeatures[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

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[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

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[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

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

signal rememberLastWidgetValueChanged[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

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[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

signal zoomToFeatures[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.