Class: QgsVariableEditorWidget

A tree based widget for editing expression context scope variables.

The widget allows editing variables from a QgsExpressionContextScope, and can optionally also show inherited variables from a QgsExpressionContext.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsVariableEditorWidget

Base classes

QWidget

QObject

QPaintDevice

Methods

context

Returns the current expression context for the widget.

editableScope

Returns the current editable scope for the widget.

reloadContext

Reloads all scopes from the editor's current context.

setContext

Overwrites the QgsExpressionContext for the widget.

setEditableScopeIndex

Sets the editable scope for the widget.

setSettingGroup

Sets the setting group for the widget.

settingGroup

Returns the setting group for the widget.

variablesInActiveScope

Returns a map variables set within the editable scope.

Signals

scopeChanged

Emitted when the user has modified a scope using the widget.

class qgis.gui.QgsVariableEditorWidget[source]

Bases: QWidget

__init__(parent: QWidget | None = None)

Constructor for QgsVariableEditorWidget.

Parameters:

parent (Optional[QWidget] = None) – parent widget

context(self) QgsExpressionContext | None[source]

Returns the current expression context for the widget. QgsVariableEditorWidget widgets are created with an empty context by default.

See also

setContext()

Return type:

Optional[QgsExpressionContext]

editableScope(self) QgsExpressionContextScope | None[source]

Returns the current editable scope for the widget.

Return type:

Optional[QgsExpressionContextScope]

Returns:

editable scope, or None if no editable scope is set

reloadContext(self)[source]

Reloads all scopes from the editor’s current context. This method should be called after adding or removing scopes from the attached context.

See also

context()

signal scopeChanged[source]

Emitted when the user has modified a scope using the widget.

setContext(self, context: QgsExpressionContext | None)[source]

Overwrites the QgsExpressionContext for the widget. Setting a context allows the widget to show all inherited variables for the context, and highlight any overridden variables within scopes.

Parameters:

context (Optional[QgsExpressionContext]) – expression context

See also

context()

setEditableScopeIndex(self, scopeIndex: int)[source]

Sets the editable scope for the widget. Only variables from the editable scope can be modified by users.

Parameters:

scopeIndex (int) – index of current editable scope. Set to -1 to disable editing and make the widget read-only.

See also

editableScope()

setSettingGroup(self, group: str | None)[source]

Sets the setting group for the widget. QgsVariableEditorWidget widgets with the same setting group will synchronise their settings, e.g., the size of columns in the tree widget.

Parameters:

group (Optional[str]) – setting group

See also

settingGroup()

settingGroup(self) str[source]

Returns the setting group for the widget. QgsVariableEditorWidget widgets with the same setting group will synchronise their settings, e.g., the size of columns in the tree widget.

Return type:

str

Returns:

setting group name

variablesInActiveScope(self) Dict[str, Any][source]

Returns a map variables set within the editable scope. Read only variables are not returned. This method can be used to retrieve the variables edited an added by users via the widget.

Return type:

Dict[str, Any]