- Extending Qt Creator Manual
- QtCreator
- Command
- Extending Qt Creator Manual 12.0.1

# Command Class

class Core::Command

The Command class represents an action, such as a menu item, tool button, or shortcut. More...

Header: | #include <coreplugin/actionmanager/command.h>

## Detailed Description

You do not create Command objects directly, but use ActionManager::registerAction() to register an action and retrieve a Command. The Command object represents the user visible action and its properties. If multiple actions are registered with the same ID (but different contexts) the returned Command is the shared one between these actions.

A Command has two basic properties: a list of default shortcuts and a default text. The default shortcuts are key sequence that the user can use to trigger the active action that the Command represents. The first shortcut in that list is the main shortcut that is for example also shown in tool tips and menus. The default text is used for representing the Command in the keyboard shortcut preference pane. If the default text is empty, the text of the visible action is used.

The user visible action is updated to represent the state of the active action (if any). For performance reasons only the enabled and visible state are considered by default though. You can tell a Command to also update the actions icon and text by setting the corresponding attribute.

If there is no active action, the default behavior of the visible action is to be disabled. You can change that behavior to make the visible action hide instead via the Command's attributes.

See The Action Manager and Commands for an overview of how Core::Command and Core::ActionManager interact.

See also Core::ActionManager and The Action Manager and Commands.