MenuAction:
Filter:
Classes | GUI

MenuAction

An individual menu or toolbar item, that performs an action when clicked.
Location: NOT INSTALLED!

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

.new

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.

.separator

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

Instance Methods

.string

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:

A String

.menu

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

Arguments:

A Menu

.shortcut

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:

A String

.checked

Indicates whether the action is checked or unchecked.

Arguments:

A boolean.

.toolTip

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

Arguments:

A String

.separator

Indicates whether the action is a separator.

Arguments:

A Boolean.

.iconVisible

Indicates whether the icon for this action will be visible.

Arguments:

A Boolean.

.checkable

Indicates that the action shows a checkbox and is checkable.

Arguments:

A Boolean

.enabled

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

Arguments:

A Boolean

.icon

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

Arguments:

An Image

.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:

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

Examples

Simple checkable menu item

Action help strings

A more complex example