MenuAction:
Filter:
Classes | GUI

MenuAction : AbstractMenuAction : QObject : Object

An individual menu or toolbar item, that performs an action when clicked.
Source: Menu.sc

Description

A MenuAction represents a single action that can occupy multiple Menus or a ToolBars, and will evaluate a function when activated. When added to a menu, these are displayed as menu items. When added to a toolbar, they appear as buttons.

Class Methods

MenuAction.new(string, function)

Create a new Action. Note that one action may occupy multiple menus and toolbars.

Arguments:

string

The name of the action. This will be its display name if added to a menu.

function

A function to perform when the action is activated.

MenuAction.separator(string)

An action that represents a menu or toolbar separator. These are not selectable or clickable.

Arguments:

string

A label for the separator. These are not always visible, depending on your OS and context.

Inherited class methods

Undocumented class methods

MenuAction.qtClass

Instance Methods

.string

.string = str

From superclass: AbstractMenuAction

A string representing the name of the action. This is used as text when it is placed in menus, and on toolbars if it does not have an icon.

Arguments:

str

A String

.menu

.menu = b

From superclass: AbstractMenuAction

A Menu. If present, this action acts as a submenu, or a pop-up menu when placed on a toolbar.

Arguments:

b

A Menu

.shortcut

.shortcut = str

From superclass: AbstractMenuAction

A string representing the keyboard shortcut to trigger this action. Keyboard shortcuts are available when an action is attached to a ToolBar, or when it's part of the context menu for a View (see View: -setContextMenuActions) Shortcut strings are of the form e.g. "Ctrl+M", "Shift+Alt+space" etc. See https://doc.qt.io/qt-5/qkeysequence.html#details for more info.

Arguments:

str

A String

.checked

.checked = b

Indicates whether the action is checked or unchecked.

Arguments:

b

A boolean.

.toolTip

.toolTip = str

A string to display when hovering over the menu item / button.

Arguments:

str

A String

.separator

.separator = b

Indicates whether the action is a separator.

Arguments:

b

A Boolean.

.iconVisible

.iconVisible = b

Indicates whether the icon for this action will be visible.

Arguments:

b

A Boolean.

.checkable

.checkable = b

Indicates that the action shows a checkbox and is checkable.

Arguments:

b

A Boolean

.enabled

.enabled = b

Indicates that the action is enabled; otherwise it will be greyed out and uninteractive.

Arguments:

b

A Boolean

.icon = icon

An Image associated with the action - to be shown next to the name of the action in both menus and toolbars.

Arguments:

icon

An Image

.font

.font = font

The font used to display the action's name. Note that special fonts may or may not be displayed depending on OS and context (e.g. system menu, context menu, toolbar). For example, OSX application menus will honor italicized fonts, but not the font family itself.

Arguments:

font

A Font

Events

Menu actions broadcast several kinds of events that can be registered for with the standard Object: -addDependant calls. Events broadcast by menu:

Events example

Inherited instance methods

Undocumented instance methods

.asMenu

Examples

Simple checkable menu item

Action help strings

A more complex example