Core::IContext Class | Extending Qt Creator Manual
Description: The IContext class associates a widget with a context list and context help.

- Extending Qt Creator Manual
- QtCreator
- IContext
- Extending Qt Creator Manual 18.0.2

# Core::IContext Class

class Core::IContext

The IContext class associates a widget with a context list and context help. More...

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

- List of all members, including inherited members

## Public Types

| HelpCallback

## Public Functions

| IContext(QObject *parent = nullptr)
Core::Context | context() const
void | contextHelp(const Core::IContext::HelpCallback &callback) const
void | setContext(const Core::Context &context)
void | setContextHelp(const Core::HelpItem &id)
void | setWidget(QWidget *widget)
QWidget * | widget() const

## Detailed Description

An instance of IContext must be registered with Core::ICore::addContextObject() to have an effect. For many subclasses of IContext, like Core::IEditor and Core::IMode, this is done automatically. But instances of IContext can be created manually to associate a context and context help for an arbitrary widget, too. IContext instances are automatically unregistered when they are deleted. Use Core::ICore::removeContextObject() if you need to unregister an IContext instance manually.

Whenever the widget is part of the application wide focus widget's parent chain, the associated context list is made active. This makes actions active that were registered for any of the included context IDs. If the user requests context help, the top-most IContext instance in the focus widget's parent hierarchy is asked to provide it.

See The Action Manager and Commands for an overview of how contexts are used for managing actions.

See also Core::ICore, Core::Context, Core::ActionManager, and The Action Manager and Commands.

## Member Type Documentation

### `[alias]` IContext::HelpCallback

The HelpCallback class defines the callback function that is used to report the help item to show when the user requests context help.

## Member Function Documentation

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

Creates an IContext with an optional parent.

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

Returns the context list associated with this IContext.

See also setContext().

### void IContext::contextHelp(const Core::IContext::HelpCallback &callback) const

Called when the user requests context help and this IContext is the top-most in the application focus widget's parent hierarchy. Implementations must call the passed callback with the resulting help item. The default implementation returns an help item with the help ID that was set with setContextHelp().

See also setContextHelp().

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

Sets the context list associated with this IContext to context.

See also context().

### void IContext::setContextHelp(const Core::HelpItem &id)

Sets the context help item associated with this IContext to id.

See also contextHelp().

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

Sets the widget associated with this IContext to widget.

See also widget().

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

Returns the widget associated with this IContext.

See also setWidget().