Class: QgsEditFormConfig

class qgis.core.QgsEditFormConfig

Bases: sip.wrapper

Contains configuration settings for an editor form.

QgsEditFormConfig(o: QgsEditFormConfig) Copy constructor

QgsEditFormConfig() Create a new edit form config. Normally invoked by QgsVectorLayer

Enums

DataDefinedProperty

Bases: enum.IntEnum

EditorLayout

alias of AttributeFormLayout

FeatureFormSuppress

alias of AttributeFormSuppression

PythonInitCodeSource

alias of AttributeFormPythonInitCodeSource

Methods

addTab

Adds a new element to the invisible root container in the layout.

attributeEditorElementFromDomElement

Deserialize drag and drop designer elements.

clearTabs

Clears all the tabs for the attribute editor form with EditorLayout.TabLayout.

dataDefinedFieldProperties

Returns data defined properties for fieldName

initCode

Gets Python code for edit form initialization.

initCodeSource

Returns Python code source for edit form initialization (if it shall be loaded from a file, read from the provided dialog editor or inherited from the environment)

initFilePath

Gets Python external file path for edit form initialization.

initFunction

Gets Python function for edit form initialization.

invisibleRootContainer

Gets the invisible root container for the drag and drop designer form (EditorLayout.TabLayout).

labelOnTop

If this returns True, the widget at the given index will receive its label on the previous line while if it returns False, the widget will receive its label on the left hand side.

layout

Gets the active layout style for the attribute editor for this layer

propertyDefinitions

Returns data defined property definitions.

readOnly

This returns True if the field is manually set to read only or if the field does not support editing like joins or virtual fields.

readXml

Read XML information Deserialize on project load

removeWidgetConfig

Remove the configuration for the editor widget with the given name

reuseLastValue

If this returns True, the widget at the given index will remember the previously entered value from this QGIS session when creating new features.

setDataDefinedFieldProperties

Set data defined properties for fieldName to properties

setInitCode

Set Python code for edit form initialization.

setInitCodeSource

Sets if Python code shall be used for edit form initialization and its origin

setInitFilePath

Set Python external file path for edit form initialization.

setInitFunction

Set Python function for edit form initialization.

setLabelOnTop

If this is set to True, the widget at the given index will receive its label on the previous line while if it is set to False, the widget will receive its label on the left hand side.

setLayout

Sets the active layout style for the attribute editor for this layer

setReadOnly

If set to False, the widget at the given index will be read-only.

setReuseLastValue

Sets whether the widget at the given index will remember the previously entered value from this QGIS session when creating new features.

setSuppress

Sets type of feature form pop-up suppression after feature creation (overrides app setting)

setUiForm

Set path to the .ui form.

setWidgetConfig

Set the editor widget config for a widget which is not for a simple field.

suppress

Type of feature form pop-up suppression after feature creation (overrides app setting)

tabs

Returns a list of tabs for EditorLayout.TabLayout obtained from the invisible root container.

uiForm

Returns the path or URL to the .ui form.

widgetConfig

Gets the configuration for the editor widget with the given name.

writeXml

Write XML information Serialize on project save

Attributes

staticMetaObject

class DataDefinedProperty(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: enum.IntEnum

Data defined properties. Form data defined overrides are stored in a property collection and they can be retrieved using the indexes specified in this enum.

Added in version 3.14.

  • NoProperty: No property

  • AllProperties: All properties for item

  • Alias: Alias

  • Editable: Editable state

Added in version 3.30.

EditorLayout

alias of AttributeFormLayout

FeatureFormSuppress

alias of AttributeFormSuppression

class GroupData

Bases: sip.wrapper

Constructor for GroupData

QgsEditFormConfig.GroupData(name: Optional[str], fields: Iterable[Optional[str]])

QgsEditFormConfig.GroupData(a0: QgsEditFormConfig.GroupData)

mFields
mName
PythonInitCodeSource

alias of AttributeFormPythonInitCodeSource

class TabData

Bases: sip.wrapper

Constructor for TabData

QgsEditFormConfig.TabData(name: Optional[str], fields: Iterable[Optional[str]], groups: Iterable[QgsEditFormConfig.GroupData])

QgsEditFormConfig.TabData(a0: QgsEditFormConfig.TabData)

mFields
mGroups
mName
addTab(self, data: QgsAttributeEditorElement | None)

Adds a new element to the invisible root container in the layout.

This is only useful in combination with EditorLayout.TabLayout.

Parameters:

data (Optional[QgsAttributeEditorElement])

attributeEditorElementFromDomElement(self, elem: QDomElement, parent: QgsAttributeEditorElement | None, layerId: str | None = '', context: QgsReadWriteContext = QgsReadWriteContext()) QgsAttributeEditorElement | None

Deserialize drag and drop designer elements.

Deprecated since version QGIS: 3.18 use QgsAttributeEditorElement.create instead

Parameters:
Return type:

Optional[QgsAttributeEditorElement]

clearTabs(self)

Clears all the tabs for the attribute editor form with EditorLayout.TabLayout.

dataDefinedFieldProperties(self, fieldName: str | None) QgsPropertyCollection

Returns data defined properties for fieldName

Added in version 3.14.

Parameters:

fieldName (Optional[str])

Return type:

QgsPropertyCollection

initCode(self) str

Gets Python code for edit form initialization.

Return type:

str

initCodeSource(self) Qgis.AttributeFormPythonInitCodeSource

Returns Python code source for edit form initialization (if it shall be loaded from a file, read from the provided dialog editor or inherited from the environment)

Return type:

Qgis.AttributeFormPythonInitCodeSource

initFilePath(self) str

Gets Python external file path for edit form initialization.

Return type:

str

initFunction(self) str

Gets Python function for edit form initialization. Will be looked up in a Python file relative to the project folder if it includes a module name or if it’s a pure function name it will searched in the Python code set with setInitCode().

Return type:

str

invisibleRootContainer(self) QgsAttributeEditorContainer | None

Gets the invisible root container for the drag and drop designer form (EditorLayout.TabLayout).

Added in version 3.

Return type:

Optional[QgsAttributeEditorContainer]

labelOnTop(self, idx: int) bool

If this returns True, the widget at the given index will receive its label on the previous line while if it returns False, the widget will receive its label on the left hand side. Labeling on top leaves more horizontal space for the widget itself.

Parameters:

idx (int)

Return type:

bool

layout(self) Qgis.AttributeFormLayout

Gets the active layout style for the attribute editor for this layer

Return type:

Qgis.AttributeFormLayout

propertyDefinitions() Dict[int, QgsPropertyDefinition]

Returns data defined property definitions.

Added in version 3.14.

Return type:

Dict[int, QgsPropertyDefinition]

readOnly(self, idx: int) bool

This returns True if the field is manually set to read only or if the field does not support editing like joins or virtual fields.

Parameters:

idx (int)

Return type:

bool

readXml(self, node: QDomNode, context: QgsReadWriteContext)

Read XML information Deserialize on project load

Parameters:
removeWidgetConfig(self, widgetName: str | None) bool

Remove the configuration for the editor widget with the given name

Parameters:

widgetName (Optional[str]) – The name of the widget.

Return type:

bool

Returns:

True if a configuration has been removed

reuseLastValue(self, index: int) bool

If this returns True, the widget at the given index will remember the previously entered value from this QGIS session when creating new features.

Added in version 3.20.

Parameters:

index (int)

Return type:

bool

setDataDefinedFieldProperties(self, fieldName: str | None, properties: QgsPropertyCollection)

Set data defined properties for fieldName to properties

Added in version 3.14.

Parameters:
setInitCode(self, code: str | None)

Set Python code for edit form initialization. Make sure that you also set the appropriate function name in setInitFunction().

Parameters:

code (Optional[str])

setInitCodeSource(self, initCodeSource: Qgis.AttributeFormPythonInitCodeSource)

Sets if Python code shall be used for edit form initialization and its origin

Parameters:

initCodeSource (Qgis.AttributeFormPythonInitCodeSource)

setInitFilePath(self, filePath: str | None)

Set Python external file path for edit form initialization. Make sure that you also set the appropriate function name in setInitFunction().

Parameters:

filePath (Optional[str])

setInitFunction(self, function: str | None)

Set Python function for edit form initialization. Will be looked up in a Python file relative to the project folder if it includes a module name or if it’s a pure function name it will searched in the Python code set with setInitCode().

Parameters:

function (Optional[str])

setLabelOnTop(self, idx: int, onTop: bool)

If this is set to True, the widget at the given index will receive its label on the previous line while if it is set to False, the widget will receive its label on the left hand side. Labeling on top leaves more horizontal space for the widget itself.

Parameters:
  • idx (int)

  • onTop (bool)

setLayout(self, editorLayout: Qgis.AttributeFormLayout)

Sets the active layout style for the attribute editor for this layer

Parameters:

editorLayout (Qgis.AttributeFormLayout)

setReadOnly(self, idx: int, readOnly: bool = True)

If set to False, the widget at the given index will be read-only.

Parameters:
  • idx (int)

  • readOnly (bool = True)

setReuseLastValue(self, index: int, reuse: bool)

Sets whether the widget at the given index will remember the previously entered value from this QGIS session when creating new features.

See also

reuseLastValue()

Added in version 3.20.

Parameters:
  • index (int)

  • reuse (bool)

setSuppress(self, s: Qgis.AttributeFormSuppression)

Sets type of feature form pop-up suppression after feature creation (overrides app setting)

Parameters:

s (Qgis.AttributeFormSuppression)

setUiForm(self, ui: str | None)

Set path to the .ui form. When a string is provided in ui, the layout style will be set to EditorLayout.UiFileLayout, if an empty or a null string is provided, the layout style will be set to EditorLayout.GeneratedLayout. If ui is a URL, a local copy of the file will be made and will be used to create the forms context is provided to save error messages

Parameters:

ui (Optional[str])

setWidgetConfig(self, widgetName: str | None, config: Dict[str, Any]) bool

Set the editor widget config for a widget which is not for a simple field.

Example

editFormConfig = layer.editFormConfig()
editFormConfig.setWidgetConfig( 'relation_id', { 'nm-rel': 'other_relation' } )
layer.setEditFormConfig(editFormConfig)
type widgetName:

Optional[str]

param widgetName:

The name of the widget to configure

type config:

Dict[str

param config:

The config to set for this widget

rtype:

bool

return:

False if a field exists with the provided widgetName. In this case QgsVectorLayer.setEditorWidgetSetup should be used.

staticMetaObject = <PyQt5.QtCore.QMetaObject object>
suppress(self) Qgis.AttributeFormSuppression

Type of feature form pop-up suppression after feature creation (overrides app setting)

Return type:

Qgis.AttributeFormSuppression

tabs(self) List[QgsAttributeEditorElement]

Returns a list of tabs for EditorLayout.TabLayout obtained from the invisible root container.

Return type:

List[QgsAttributeEditorElement]

uiForm(self) str

Returns the path or URL to the .ui form. Only meaningful with EditorLayout.UiFileLayout

Return type:

str

widgetConfig(self, widgetName: str | None) Dict[str, Any]

Gets the configuration for the editor widget with the given name.

Parameters:

widgetName (Optional[str]) – The name of the widget.

Return type:

Dict[str, Any]

Returns:

The configuration for the editor widget or an empty config if the field does not exist

writeXml(self, node: QDomNode, context: QgsReadWriteContext)

Write XML information Serialize on project save

Parameters: