Class: QgsAttributeForm¶
The attribute form widget for vector layer features.
Class Hierarchy¶
Base classes¶
- 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
geometryof 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
layertaking into account attribute form-specific context such as the remembrance and reuse of last attribute values.Added in version 4.0.
- Parameters:
layer (Optional[QgsVectorLayer])
geometry (QgsGeometry)
attributes (Dict[int, Any])
context (QgsExpressionContext)
- Return type:
- 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:
- 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
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:
Trueif the event has been handled (key was ESC)
- feature(self) QgsFeature¶
Returns feature of attribute form.
- Return type:
- 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
QgsAttributeEditorContextin 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
- Return type:
- 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
Trueif any of the form widgets need feature geometryAdded 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
attributevalue in the parent form has changed tonewValue.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)
- 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.
- save(self) bool[source]¶
Save all the values from the editors to the layer.
- Return type:
bool
- Returns:
Trueif successful
- saveWithDetails(self)[source]¶
Save all the values from the editors to the layer.
- Returns:
Trueif save was successfulerror: 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
- 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
QgsAttributeEditorContextin 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.