Core::IMode Class | Extending Qt Creator Manual
Description: The IMode class represents a mode in Qt Creator.

- Extending Qt Creator Manual
- QtCreator
- IMode
- Extending Qt Creator Manual 18.0.2

# Core::IMode Class

class Core::IMode

The IMode class represents a mode in Qt Creator. More...

Header: | `#include <coreplugin/imode.h>`
Inherits: | QObject
Inherited By: | Core::DesignMode

- List of all members, including inherited members

## Properties

displayName : QString enabled : bool icon : QIcon | id : Utils::Id priority : int

## Public Functions

| IMode(QObject *parent = nullptr)
void | addToMenu(QMenu *menu) const
Core::Context | context() const
QString | displayName() const
bool | hasMenu() const
QIcon | icon() const
Utils::Id | id() const
bool | isEnabled() const
int | priority() const
void | setContext(const Core::Context &context)
void | setDisplayName(const QString &displayName)
void | setEnabled(bool enabled)
void | setIcon(const QIcon &icon)
void | setId(Utils::Id id)
void | setMenu(std::function<void (QMenu *)> menuFunction)
void | setPriority(int priority)
void | setWidget(QWidget *widget)
void | setWidgetCreator(const std::function<QWidget *()> &widgetCreator)
QWidget * | widget() const

## Signals

void | enabledStateChanged(bool enabled)

## Detailed Description

This class defines a mode and its representation as a tool button in the mode selector on the left side of Qt Creator's main window.

Modes are used to show a different UI for different development tasks. Therefore modes control the layout of most of Qt Creator's main window, except for the tool bar on the left side and the status bar. For example Edit mode, the most commonly used mode for coding, shows the code editor and various navigation and output panes. Debug mode enhances that view with a configurable layout of debugging related information. Design mode reserves all the main window's space for the graphical editor.

When a mode gets selected, a context is added and a widget is shown. Use IMode::setContext() to set the context, and either IMode::setWidget() to set the widget directly or IMode::setWidgetCreator() to define a functor that is used when the widget is needed.

Adding a mode should be done sparingly, only as a last reserve. Consider if your feature can instead be implemented as a INavigationWidgetFactory, IOutputPane, `Debugger::Utils::Perspective`, separate dialog, or specialized IEditor first.

If you add a mode, consider adding a NavigationWidgetPlaceHolder on the left side and a OutputPanePlaceHolder on the bottom of your mode's layout.

Modes automatically register themselves with Qt Creator when they are created and unregister themselves when they are destructed.

## Property Documentation

### displayName : QString

This property holds the display name of the mode.

The display name is shown under the mode icon in the mode selector.

Access functions:

QString | displayName() const
void | setDisplayName(const QString &displayName)

### enabled : bool

This property holds whether the mode is enabled.

By default, this property is `true`.

Access functions:

bool | isEnabled() const
void | setEnabled(bool enabled)

Notifier signal:

void | enabledStateChanged(bool enabled)

### icon : QIcon

This property holds the icon of the mode.

The icon is shown for the mode in the mode selector. Mode icons should support the sizes 34x34 pixels and 68x68 pixels for HiDPI.

Access functions:

QIcon | icon() const
void | setIcon(const QIcon &icon)

### id : Utils::Id

This property holds the ID of the mode.

Access functions:

Utils::Id | id() const
void | setId(Utils::Id id)

### priority : int

This property holds the priority of the mode.

The priority defines the order in which the modes are shown in the mode selector. Higher priority moves to mode towards the top. Welcome mode, which should stay at the top, has the priority 100. The default priority is -1.

Access functions:

int | priority() const
void | setPriority(int priority)

## Member Function Documentation

### IMode::IMode(QObject *parent = nullptr)

Creates an IMode with an optional parent.

Registers the mode in Qt Creator.

### void IMode::addToMenu(QMenu *menu) const

Adds the mode specific items to the menu, if any.

See also setMenu().

### Core::Context IMode::context() const

Returns the context list associated with this IMode.

See also setContext().

### bool IMode::hasMenu() const

Returns if the mode provides mode specific context menu items.

See also setMenu().

### void IMode::setContext(const Core::Context &context)

Sets the context associated with this IMode.

See also context().

### void IMode::setMenu(std::function<void (QMenu *)> menuFunction)

Sets a menuFunction that is used to add the mode specific items to the mode's context menu. This is called every time the context menu is requested with a new QMenu instance. The menu is destroyed after the it closes.

See also hasMenu().

### void IMode::setWidget(QWidget *widget)

Sets the widget associated with this IMode.

Note: The ownership of the passed widget is not changed.

See also widget() and setWidgetCreator().

### void IMode::setWidgetCreator(const std::function<QWidget *()> &widgetCreator)

Sets the widgetCreator to create the widget associated with this IMode when needed.

Note: The mode itself takes the ownership of the created widget.

See also widget() and setWidget().

### QWidget *IMode::widget() const

Returns the widget associated with this IMode.

See also setWidget().