ActionContainer Class | Extending Qt Creator Manual

- Extending Qt Creator Manual
- ActionContainer
- Extending Qt Creator Manual 4.12.4

# ActionContainer Class

class Core::ActionContainer

The ActionContainer class represents a menu or menu bar in Qt Creator. More...

Header: | #include <ActionContainer>

- List of all members, including inherited members

## Public Types

enum | OnAllDisabledBehavior { Disable, Hide, Show }

## Public Functions

virtual void | addAction(Core::Command *action, Core::Id group = Id()) = 0
virtual void | addMenu(Core::ActionContainer *menu, Core::Id group = Core::Id()) = 0
virtual void | addMenu(Core::ActionContainer *before, Core::ActionContainer *menu) = 0
Core::Command * | addSeparator(Core::Id group = Id())
virtual Core::Command * | addSeparator(const Core::Context &context, Core::Id group = Id(), QAction **outSeparator = nullptr) = 0
virtual void | appendGroup(Core::Id group) = 0
virtual void | clear() = 0
virtual void | insertGroup(Core::Id before, Core::Id group) = 0
virtual QAction * | insertLocation(Core::Id group) const = 0
virtual QMenu * | menu() const = 0
virtual QMenuBar * | menuBar() const = 0
virtual ActionContainer::OnAllDisabledBehavior | onAllDisabledBehavior() const = 0
virtual void | setOnAllDisabledBehavior(Core::ActionContainer::OnAllDisabledBehavior behavior) = 0
virtual Utils::TouchBar * | touchBar() const = 0

## Detailed Description

You don't create instances of this class directly, but instead use the ActionManager::createMenu(), ActionManager::createMenuBar() and ActionManager::createTouchBar() functions. Retrieve existing action containers for an ID with ActionManager::actionContainer().

Within a menu or menu bar you can group menus and items together by defining groups (the order of the groups is defined by the order of the ActionContainer::appendGroup() calls), and adding menus or actions to these groups. If no custom groups are defined, an action container has three default groups `Core::Constants::G_DEFAULT_ONE`, `Core::Constants::G_DEFAULT_TWO` and `Core::Constants::G_DEFAULT_THREE`.

You can specify whether the menu represented by this action container should be automatically disabled or hidden whenever it only contains disabled items and submenus by setting the corresponding setOnAllDisabledBehavior(). The default is ActionContainer::Disable for menus, and ActionContainer::Show for menu bars.

## Member Type Documentation

### enum ActionContainer::OnAllDisabledBehavior

Defines what happens when the represented menu is empty or contains only disabled or invisible items.

Constant | Value | Description
--- | --- | ---
`Core::ActionContainer::Disable` | `0` | The menu will be visible but disabled.
`Core::ActionContainer::Hide` | `1` | The menu will not be visible until the state of the subitems changes.
`Core::ActionContainer::Show` | `2` | The menu will still be visible and active.

## Member Function Documentation

### `[pure virtual]` void ActionContainer::addAction(Core::Command *action, Core::Id group = Id())

Add the action as a menu item to this action container. The action is added as the last item of the specified group.

See also appendGroup() and addMenu().

### `[pure virtual]` void ActionContainer::addMenu(Core::ActionContainer *menu, Core::Id group = Core::Id())

Add the menu as a submenu to this action container. The menu is added as the last item of the specified group.

See also appendGroup() and addAction().

### `[pure virtual]` void ActionContainer::addMenu(Core::ActionContainer *before, Core::ActionContainer *menu)

Add menu as a submenu to this action container before the menu specified by before.

See also appendGroup() and addAction().

### Core::Command *ActionContainer::addSeparator(Core::Id group = Id())

Adds a separator to the end of group to the action container.

Returns the created separator.

### `[pure virtual]` Core::Command *ActionContainer::addSeparator(const Core::Context &context, Core::Id group = Id(), QAction **outSeparator = nullptr)

Adds a separator to the end of the given group to the action container, which is enabled for a given context. Returns the created separator action, outSeparator.

### `[pure virtual]` void ActionContainer::appendGroup(Core::Id group)

Adds group to the action container.

Use groups to segment your action container into logical parts. You can add actions and menus directly into groups.

See also addAction() and addMenu().

### `[pure virtual]` void ActionContainer::clear()

Clears this menu and submenus from all actions and submenus. However, does does not destroy the submenus and commands, just removes them from their parents.

### `[pure virtual]` void ActionContainer::insertGroup(Core::Id before, Core::Id group)

Inserts group to the action container before the group specified by before.

### `[pure virtual]` QAction *ActionContainer::insertLocation(Core::Id group) const

Returns an action representing the group, that could be used with `QWidget::insertAction`.

### `[pure virtual]` QMenu *ActionContainer::menu() const

Returns the QMenu instance that is represented by this action container, or 0 if this action container represents a menu bar.

### `[pure virtual]` QMenuBar *ActionContainer::menuBar() const

Returns the QMenuBar instance that is represented by this action container, or 0 if this action container represents a menu.

### `[pure virtual]` ActionContainer::OnAllDisabledBehavior ActionContainer::onAllDisabledBehavior() const

Returns the behavior of the menu represented by this action container for the case whenever it only contains disabled items and submenus. The default is ActionContainer::Disable for menus, and ActionContainer::Show for menu bars.

See also OnAllDisabledBehavior and setOnAllDisabledBehavior().

### `[pure virtual]` void ActionContainer::setOnAllDisabledBehavior(Core::ActionContainer::OnAllDisabledBehavior behavior)

Defines the behavior of the menu represented by this action container for the case whenever it only contains disabled items and submenus. The default is ActionContainer::Disable for menus, and ActionContainer::Show for menu bars.

See also ActionContainer::OnAllDisabledBehavior and ActionContainer::onAllDisabledBehavior().

### `[pure virtual]` Utils::TouchBar *ActionContainer::touchBar() const

Returns the touch bar that is represented by this action container.