Class: QgsActionMenu

This class is a menu that is populated automatically with the actions defined for a given layer.

QgsActionMenu showing some sample actions for a feature

QgsActionMenu showing some sample actions for a feature

Class Hierarchy

Inheritance diagram of qgis.gui.QgsActionMenu

Base classes

QMenu

QWidget

QObject

QPaintDevice

Enums

ActionType

Action types.

Methods

expressionContextScope

Returns an expression context scope used to resolve underlying actions.

isEmpty

Returns True if the menu has no valid actions.

menuActions

Returns menu actions

setActionContextGenerator

Sets a QgsMapLayerActionContextGenerator to create action contexts for the menu.

setExpressionContextScope

Sets an expression context scope used to resolve underlying actions.

setFeature

Change the feature on which actions are performed

setMode

Change the mode of the actions

Signals

reinit

Emitted after actions have been reloaded.

class qgis.gui.QgsActionMenu[source]

Bases: QMenu

__init__(layer: QgsVectorLayer | None, feature: QgsFeature, actionScope: str | None, parent: QWidget | None = None)

Constructs a new QgsActionMenu

Parameters:
  • layer (Optional[QgsVectorLayer]) – The layer that this action will be run upon.

  • feature (QgsFeature) – The feature that this action will be run upon. Make sure that this feature is available for the lifetime of this object.

  • parent (Optional[QWidget] = None) – The usual QWidget parent.

  • actionScope (Optional[str]) – The action scope this menu will run in

__init__(layer: QgsVectorLayer | None, fid: int, actionScope: str | None, parent: QWidget | None = None)

Constructs a new QgsActionMenu

Parameters:
  • layer (Optional[QgsVectorLayer]) – The layer that this action will be run upon.

  • fid (int) – The feature id of the feature for which this action will be run.

  • parent (Optional[QWidget] = None) – The usual QWidget parent.

  • actionScope (Optional[str]) – The action scope this menu will run in

class ActionData
class ActionData(action: QgsAction, featureId: int, mapLayer: QgsMapLayer | None)
class ActionData(action: QgsMapLayerAction | None, featureId: int, mapLayer: QgsMapLayer | None)
class ActionData(a0: QgsActionMenu.ActionData)

Bases: object

actionData
actionType
featureId
mapLayer
class ActionType(*values)

Bases: IntEnum

Action types.

Prior to QGIS 3.30 this was available as QgsActionMenu.ActionType

Added in version 3.30.

  • Invalid: Invalid

  • MapLayerAction: Standard actions (defined by core or plugins), corresponds to QgsMapLayerAction class.

  • AttributeAction: Custom actions (manually defined in layer properties), corresponds to QgsAction class.

expressionContextScope(self) QgsExpressionContextScope[source]

Returns an expression context scope used to resolve underlying actions.

Return type:

QgsExpressionContextScope

isEmpty(self) bool[source]

Returns True if the menu has no valid actions.

Added in version 3.30.

Return type:

bool

menuActions(self) List[QgsAction]

Returns menu actions

Added in version 3.12.

Return type:

List[QgsAction]

signal reinit[source]

Emitted after actions have been reloaded.

setActionContextGenerator(self, generator: QgsMapLayerActionContextGenerator | None)[source]

Sets a QgsMapLayerActionContextGenerator to create action contexts for the menu.

The generator object must exist for the lifetime of the menu.

Added in version 3.30.

Parameters:

generator (Optional[QgsMapLayerActionContextGenerator])

setExpressionContextScope(self, scope: QgsExpressionContextScope)[source]

Sets an expression context scope used to resolve underlying actions.

Parameters:

scope (QgsExpressionContextScope)

setFeature(self, feature: QgsFeature)[source]

Change the feature on which actions are performed

Parameters:

feature (QgsFeature) – A feature. Will not take ownership. It’s the callers responsibility to keep the feature as long as the menu is displayed and the action is running.

setMode(self, mode: QgsAttributeEditorContext.Mode)[source]

Change the mode of the actions

Parameters:

mode (QgsAttributeEditorContext.Mode) – The mode of the attribute form