Class: QgsActionMenu

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

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 messageDiscarded[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 messageEmitted[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 reinit[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.

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