ActionContainer Class

class Core::ActionContainer

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

Header: #include <coreplugin/actionmanager/actioncontainer.h>
Inherits: QObject

Public Types

enum OnAllDisabledBehavior { Disable, Hide, Show }

Public Functions

virtual void addAction(Core::Command *action, Utils::Id group = Id()) = 0
virtual void addMenu(Core::ActionContainer *menu, Utils::Id group = Utils::Id()) = 0
virtual void addMenu(Core::ActionContainer *before, Core::ActionContainer *menu) = 0
Core::Command *addSeparator(Utils::Id group = {})
virtual Core::Command *addSeparator(const Core::Context &context, Utils::Id group = {}, QAction **outSeparator = nullptr) = 0
virtual void appendGroup(Utils::Id group) = 0
virtual void clear() = 0
virtual void insertGroup(Utils::Id before, Utils::Id group) = 0
virtual QAction *insertLocation(Utils::Id group) const = 0
virtual QMenu *menu() const = 0
virtual QMenuBar *menuBar() const = 0
virtual Core::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.

ConstantValueDescription
Core::ActionContainer::Disable0The menu will be visible but disabled.
Core::ActionContainer::Hide1The menu will not be visible until the state of the subitems changes.
Core::ActionContainer::Show2The menu will still be visible and active.

Member Function Documentation

[pure virtual] void ActionContainer::addAction(Core::Command *action, Utils::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, Utils::Id group = Utils::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(Utils::Id group = {})

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, Utils::Id group = {}, 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(Utils::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(Utils::Id before, Utils::Id group)

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

[pure virtual] QAction *ActionContainer::insertLocation(Utils::Id group) const

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

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

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

[pure virtual] Core::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.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.