Class: QgsAttributeForm

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

Bases: PyQt5.QtWidgets.QWidget

Methods

actionEvent

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.

changeEvent

childEvent

closeEvent

connectNotify

contextMenuEvent

create

currentFormFeature

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

customEvent

destroy

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

disconnectNotify

displayWarning

Displays a warning message in the form message bar

dragEnterEvent

dragLeaveEvent

dragMoveEvent

dropEvent

editable

Returns if the form is currently in editable mode.

enterEvent

event

eventFilter

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

feature

rtype:

QgsFeature

focusInEvent

focusNextChild

focusNextPrevChild

focusOutEvent

focusPreviousChild

hideButtonBox

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

hideEvent

initPainter

inputMethodEvent

isSignalConnected

keyPressEvent

keyReleaseEvent

layer

Returns the layer for which this form is shown

leaveEvent

metric

mode

Returns the current mode of the form.

mouseDoubleClickEvent

mouseMoveEvent

mousePressEvent

mouseReleaseEvent

moveEvent

nativeEvent

needsGeometry

Returns True if any of the form widgets need feature geometry

paintEvent

parentFormValueChanged

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

receivers

refreshFeature

reload current feature

resetSearch

Resets the search/filter form values.

resetValues

Sets all values to the values of the current feature

resizeEvent

save

Save all the values from the editors to the layer.

saveWithDetails

Save all the values from the editors to the layer.

sender

senderSignalIndex

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

sharedPainter

showButtonBox

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

showEvent

tabletEvent

timerEvent

updateMicroFocus

wheelEvent

Signals

attributeChanged

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

closed

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

featureSaved

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

filterExpressionSet

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

flashFeatures

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

modeChanged

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

openFilteredFeaturesAttributeTable

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

widgetValueChanged

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

zoomToFeatures

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

Attributes

AddFeatureMode

AggregateSearchMode

FilterAnd

FilterOr

IdentifyMode

MultiEditMode

ReplaceFilter

SearchMode

SingleEditMode

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
actionEvent(self, QActionEvent)
addInterface(self, iface: QgsAttributeFormInterface)

Takes ownership

Parameters:

iface (QgsAttributeFormInterface) –

aggregateFilter(self) str

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.

New in version 3.0.

Return type:

str

attributeChanged

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.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

changeAttribute(self, field: str, value: Any, hintText: str = '')

Call this to change the content of a given attribute. Will update the editor(s) related to this field.

Parameters:
  • field (str) – The field to change

  • value (Any) – The new value

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

changeEvent(self, QEvent)
childEvent(self, QChildEvent)
closeEvent(self, QCloseEvent)
closed

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.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

connectNotify(self, QMetaMethod)
contextMenuEvent(self, QContextMenuEvent)
create(self, window: PyQt5.sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)
currentFormFeature(self) QgsFeature

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

New in version 3.16.

Return type:

QgsFeature

customEvent(self, QEvent)
destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)
disconnectButtonBox(self)

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

disconnectNotify(self, QMetaMethod)
displayWarning(self, message: str)

Displays a warning message in the form message bar

Parameters:

message (str) – message string

See also

mode()

New in version 3.12.

dragEnterEvent(self, QDragEnterEvent)
dragLeaveEvent(self, QDragLeaveEvent)
dragMoveEvent(self, QDragMoveEvent)
dropEvent(self, QDropEvent)
editable(self) bool

Returns if the form is currently in editable mode.

Return type:

bool

Returns:

Editable mode of this form

enterEvent(self, QEvent)
event(self, QEvent) bool
eventFilter(self, object: QObject, event: QEvent) bool

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

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

  • event (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

featureSaved

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.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

filterExpressionSet

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.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

flashFeatures

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.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

focusInEvent(self, QFocusEvent)
focusNextChild(self) bool
focusNextPrevChild(self, bool) bool
focusOutEvent(self, QFocusEvent)
focusPreviousChild(self) bool
hideButtonBox(self)

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

Note

set Embed in QgsAttributeEditorContext in constructor instead

hideEvent(self, QHideEvent)
initPainter(self, QPainter)
inputMethodEvent(self, QInputMethodEvent)
isSignalConnected(self, QMetaMethod) bool
keyPressEvent(self, QKeyEvent)
keyReleaseEvent(self, QKeyEvent)
layer(self) QgsVectorLayer

Returns the layer for which this form is shown

Return type:

QgsVectorLayer

Returns:

Layer

leaveEvent(self, QEvent)
metric(self, QPaintDevice.PaintDeviceMetric) int
mode(self) QgsAttributeEditorContext.Mode

Returns the current mode of the form.

See also

setMode()

New in version 2.16.

Return type:

QgsAttributeEditorContext.Mode

modeChanged

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.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

mouseDoubleClickEvent(self, QMouseEvent)
mouseMoveEvent(self, QMouseEvent)
mousePressEvent(self, QMouseEvent)
mouseReleaseEvent(self, QMouseEvent)
moveEvent(self, QMoveEvent)
nativeEvent(self, Union[QByteArray, bytes, bytearray], PyQt5.sip.voidptr) Tuple[bool, int]
needsGeometry(self) bool

Returns True if any of the form widgets need feature geometry

New in version 3.20.

Return type:

bool

openFilteredFeaturesAttributeTable

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.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

paintEvent(self, QPaintEvent)
parentFormValueChanged(self, attribute: str, newValue: Any)

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.

New in version 3.14.

Parameters:
  • attribute (str) –

  • newValue (Any) –

receivers(self, PYQT_SIGNAL) int
refreshFeature(self)

reload current feature

resetSearch(self)

Resets the search/filter form values.

New in version 2.16.

resetValues(self)

Sets all values to the values of the current feature

resizeEvent(self, QResizeEvent)
save(self) bool

Save all the values from the editors to the layer.

Return type:

bool

Returns:

True if successful

saveWithDetails(self) Tuple[bool, str]

Save all the values from the editors to the layer.

Return type:

Tuple[bool, str]

Returns:

  • True if save was successful

  • error: will be set to an explanatory error message if an error occurs while saving the form.

New in version 3.18.

sender(self) QObject
senderSignalIndex(self) int
setEditCommandMessage(self, message: str)

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

Parameters:

message (str) – The message

setExtraContextScope(self, extraScope: QgsExpressionContextScope)

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

New in version 3.16.

Parameters:

extraScope (QgsExpressionContextScope) –

setFeature(self, feature: QgsFeature)

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)

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 (QgsMessageBar) – target message bar

New in version 2.16.

setMode(self, mode: QgsAttributeEditorContext.Mode)

Sets the current mode of the form.

Parameters:

mode (QgsAttributeEditorContext.Mode) – form mode

See also

mode()

New in version 2.16.

setMultiEditFeatureIds(self, fids: object)

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

Parameters:

fids (object) – feature ID list

New in version 2.16.

sharedPainter(self) QPainter
showButtonBox(self)

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

Note

set Embed in QgsAttributeEditorContext in constructor instead

showEvent(self, QShowEvent)
tabletEvent(self, QTabletEvent)
timerEvent(self, QTimerEvent)
updateMicroFocus(self)
wheelEvent(self, QWheelEvent)
widgetValueChanged

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.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

zoomToFeatures

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.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL