- Qt 6.6
- Qt GUI
- C++ Classes
- QIconEngine
- Qt 6.6.0 Reference Documentation

# QIconEngine Class

The QIconEngine class provides an abstract base class for QIcon renderers. More...

Header: | #include <QIconEngine>
CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: | QT += gui

- List of all members, including inherited members
- QIconEngine is part of Painting Classes.

## Public Types

struct | ScaledPixmapArgument
enum | IconEngineHook { IsNullHook, ScaledPixmapHook }

## Public Functions

| QIconEngine()
virtual | ~QIconEngine()
virtual QSize | actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state)
virtual void | addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state)
virtual void | addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state)
virtual QList<QSize> | availableSizes(QIcon::Mode mode = QIcon::Normal, QIcon::State state = QIcon::Off)
virtual QIconEngine * | clone() const = 0
virtual QString | iconName()
virtual bool | isNull()
virtual QString | key() const
virtual void | paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) = 0
virtual QPixmap | pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
virtual bool | read(QDataStream &in)
virtual QPixmap | scaledPixmap(const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale)
virtual void | virtual_hook(int id, void *data)
virtual bool | write(QDataStream &out) const

## Detailed Description

An icon engine provides the rendering functions for a QIcon. Each icon has a corresponding icon engine that is responsible for drawing the icon with a requested size, mode and state.

The icon is rendered by the paint() function, and the icon can additionally be obtained as a pixmap with the pixmap() function (the default implementation simply uses paint() to achieve this). The addPixmap() function can be used to add new pixmaps to the icon engine, and is used by QIcon to add specialized custom pixmaps.

The paint(), pixmap(), and addPixmap() functions are all virtual, and can therefore be reimplemented in subclasses of QIconEngine.

See also QIconEnginePlugin.

## Member Type Documentation

### enum QIconEngine::IconEngineHook

These enum values are used for virtual_hook() to allow additional queries to icon engine without breaking binary compatibility.

Constant | Value | Description
--- | --- | ---
`QIconEngine::IsNullHook` | `3` | Allow to query if this engine represents a null icon. The data argument of the virtual_hook() is a pointer to a bool that can be set to true if the icon is null. This enum value was added in Qt 5.7.
`QIconEngine::ScaledPixmapHook` | `4` | Provides a way to get a pixmap that is scaled according to the given scale (typically equal to the device pixel ratio). The data argument of the virtual_hook() function is a ScaledPixmapArgument pointer that contains both the input and output arguments. This enum value was added in Qt 5.9.

See also virtual_hook().

## Member Function Documentation

### QIconEngine::QIconEngine()

Constructs the icon engine.

### `[virtual noexcept]` QIconEngine::~QIconEngine()

Destroys the icon engine.

### `[virtual]` QSize QIconEngine::actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state)

Returns the actual size of the icon the engine provides for the requested size, mode and state. The default implementation returns the given size.

### `[virtual]` void QIconEngine::addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state)

Called by QIcon::addFile(). Adds a specialized pixmap from the file with the given fileName, size, mode and state. The default pixmap-based engine stores any supplied file names, and it loads the pixmaps on demand instead of using scaled pixmaps if the size of a pixmap matches the size of icon requested. Custom icon engines that implement scalable vector formats are free to ignores any extra files.

### `[virtual]` void QIconEngine::addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state)

Called by QIcon::addPixmap(). Adds a specialized pixmap for the given mode and state. The default pixmap-based engine stores any supplied pixmaps, and it uses them instead of scaled pixmaps if the size of a pixmap matches the size of icon requested. Custom icon engines that implement scalable vector formats are free to ignores any extra pixmaps.

### `[virtual]` QList<QSize> QIconEngine::availableSizes(QIcon::Mode mode = QIcon::Normal, QIcon::State state = QIcon::Off)

Returns sizes of all images that are contained in the engine for the specific mode and state.

### `[pure virtual]` QIconEngine *QIconEngine::clone() const

Reimplement this method to return a clone of this icon engine.

### `[virtual]` QString QIconEngine::iconName()

Returns the name used to create the engine, if available.

### `[virtual]` bool QIconEngine::isNull()

Returns true if this icon engine represent a null QIcon.

Note: This is a helper method and the actual work is done by the virtual_hook() method, hence this method depends on icon engine support and may not work with all icon engines.

### `[virtual]` QString QIconEngine::key() const

Returns a key that identifies this icon engine.

### `[pure virtual]` void QIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state)

Uses the given painter to paint the icon with the required mode and state into the rectangle rect.

### `[virtual]` QPixmap QIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)

Returns the icon as a pixmap with the required size, mode, and state. The default implementation creates a new pixmap and calls paint() to fill it.

### `[virtual]` bool QIconEngine::read(QDataStream &in)

Reads icon engine contents from the QDataStream in. Returns true if the contents were read; otherwise returns `false`.

QIconEngine's default implementation always return false.

### `[virtual]` QPixmap QIconEngine::scaledPixmap(const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale)

Returns a pixmap for the given size, mode, state and scale.

The scale argument is typically equal to the device pixel ratio of the display.

Note: This is a helper method and the actual work is done by the virtual_hook() method, hence this method depends on icon engine support and may not work with all icon engines.

Note: Some engines may cast scale to an integer.

See also ScaledPixmapArgument.

### `[virtual]` void QIconEngine::virtual_hook(int id, void *data)

Additional method to allow extending QIconEngine without adding new virtual methods (and without breaking binary compatibility). The actual action and format of data depends on id argument which is in fact a constant from IconEngineHook enum.

See also IconEngineHook.

### `[virtual]` bool QIconEngine::write(QDataStream &out) const

Writes the contents of this engine to the QDataStream out. Returns `true` if the contents were written; otherwise returns `false`.

QIconEngine's default implementation always return false.