Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QIcon Class Reference

The QIcon class provides scalable icons in different modes and states. More...

#include <qicon.h>

+ Collaboration diagram for QIcon:

Public Types

enum  Mode { Normal , Disabled , Active , Selected }
 This enum type describes the mode for which a pixmap is intended to be used. More...
 
enum  State { On , Off }
 This enum describes the state for which a pixmap is intended to be used. More...
 
typedef QIconPrivateDataPtr
 

Public Member Functions

 QIcon () noexcept
 Constructs a null icon.
 
 QIcon (const QPixmap &pixmap)
 Constructs an icon from a pixmap.
 
 QIcon (const QIcon &other)
 Constructs a copy of other.
 
 QIcon (QIcon &&other) noexcept
 Move-constructs a QIcon instance, making it point to the same object that other was pointing to.
 
 QIcon (const QString &fileName)
 Constructs an icon from the file with the given fileName.
 
 QIcon (QIconEngine *engine)
 Creates an icon with a specific icon engine.
 
 ~QIcon ()
 Destroys the icon.
 
QIconoperator= (const QIcon &other)
 Assigns the other icon to this icon and returns a reference to this icon.
 
void swap (QIcon &other) noexcept
 
bool operator== (const QIcon &) const =delete
 
bool operator!= (const QIcon &) const =delete
 
 operator QVariant () const
 Returns the icon as a QVariant.
 
QPixmap pixmap (const QSize &size, Mode mode=Normal, State state=Off) const
 Returns a pixmap with the requested size, mode, and state, generating one if necessary.
 
QPixmap pixmap (int w, int h, Mode mode=Normal, State state=Off) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a pixmap of size QSize(w, h).
 
QPixmap pixmap (int extent, Mode mode=Normal, State state=Off) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a pixmap of size QSize(extent, extent).
 
QPixmap pixmap (const QSize &size, qreal devicePixelRatio, Mode mode=Normal, State state=Off) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QSize actualSize (const QSize &size, Mode mode=Normal, State state=Off) const
 Returns the actual size of the icon for the requested size, mode, and state.
 
QString name () const
 
void paint (QPainter *painter, const QRect &rect, Qt::Alignment alignment=Qt::AlignCenter, Mode mode=Normal, State state=Off) const
 Uses the painter to paint the icon with specified alignment, required mode, and state into the rectangle rect.
 
void paint (QPainter *painter, int x, int y, int w, int h, Qt::Alignment alignment=Qt::AlignCenter, Mode mode=Normal, State state=Off) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Paints the icon into the rectangle QRect(x, y, w, h).
 
bool isNull () const
 Returns true if the icon is empty; otherwise returns false.
 
bool isDetached () const
 
void detach ()
 
qint64 cacheKey () const
 Returns a number that identifies the contents of this QIcon object.
 
void addPixmap (const QPixmap &pixmap, Mode mode=Normal, State state=Off)
 Adds pixmap to the icon, as a specialization for mode and state.
 
void addFile (const QString &fileName, const QSize &size=QSize(), Mode mode=Normal, State state=Off)
 Adds an image from the file with the given fileName to the icon, as a specialization for size, mode and state.
 
QList< QSizeavailableSizes (Mode mode=Normal, State state=Off) const
 
void setIsMask (bool isMask)
 
bool isMask () const
 
DataPtrdata_ptr ()
 

Static Public Member Functions

static QIcon fromTheme (const QString &name)
 
static QIcon fromTheme (const QString &name, const QIcon &fallback)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the QIcon corresponding to name in the current icon theme.
 
static bool hasThemeIcon (const QString &name)
 
static QStringList themeSearchPaths ()
 
static void setThemeSearchPaths (const QStringList &searchpath)
 
static QStringList fallbackSearchPaths ()
 
static void setFallbackSearchPaths (const QStringList &paths)
 
static QString themeName ()
 
static void setThemeName (const QString &path)
 
static QString fallbackThemeName ()
 
static void setFallbackThemeName (const QString &name)
 

Friends

Q_GUI_EXPORT QDataStreamoperator<< (QDataStream &, const QIcon &)
 
Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &, QIcon &)
 

Related Symbols

(Note that these are not member symbols.)

QDataStreamoperator<< (QDataStream &stream, const QIcon &icon)
 
QDataStreamoperator>> (QDataStream &stream, QIcon &icon)
 

Detailed Description

The QIcon class provides scalable icons in different modes and states.

\inmodule QtGui

A QIcon can generate smaller, larger, active, and disabled pixmaps from the set of pixmaps it is given. Such pixmaps are used by Qt widgets to show an icon representing a particular action.

The simplest use of QIcon is to create one from a QPixmap file or resource, and then use it, allowing Qt to work out all the required icon styles and sizes. For example:

button->setIcon(QIcon("open.xpm"));
void setIcon(const QIcon &icon)
QIcon() noexcept
Constructs a null icon.
Definition qicon.cpp:648
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition qtoolbutton.h:20
QPushButton * button
[2]

To undo a QIcon, simply set a null icon in its place:

Use the QImageReader::supportedImageFormats() and QImageWriter::supportedImageFormats() functions to retrieve a complete list of the supported file formats.

When you retrieve a pixmap using pixmap(QSize, Mode, State), and no pixmap for this given size, mode and state has been added with addFile() or addPixmap(), then QIcon will generate one on the fly. This pixmap generation happens in a QIconEngine. The default engine scales pixmaps down if required, but never up, and it uses the current style to calculate a disabled appearance. By using custom icon engines, you can customize every aspect of generated icons. With QIconEnginePlugin it is possible to register different icon engines for different file suffixes, making it possible for third parties to provide additional icon engines to those included with Qt.

Note
Since Qt 4.2, an icon engine that supports SVG is included.

Definition at line 19 of file qicon.h.

Member Typedef Documentation

◆ DataPtr

Definition at line 104 of file qicon.h.

Member Enumeration Documentation

◆ Mode

This enum type describes the mode for which a pixmap is intended to be used.

The currently defined modes are:

\value Normal Display the pixmap when the user is not interacting with the icon, but the functionality represented by the icon is available. \value Disabled Display the pixmap when the functionality represented by the icon is not available. \value Active Display the pixmap when the functionality represented by the icon is available and the user is interacting with the icon, for example, moving the mouse over it or clicking it. \value Selected Display the pixmap when the item represented by the icon is selected.

Enumerator
Normal 
Disabled 
Active 
Selected 

Definition at line 22 of file qicon.h.

◆ State

This enum describes the state for which a pixmap is intended to be used.

The state can be:

\value Off Display the pixmap when the widget is in an "off" state \value On Display the pixmap when the widget is in an "on" state

Enumerator
On 
Off 

Definition at line 23 of file qicon.h.

Constructor & Destructor Documentation

◆ QIcon() [1/6]

QIcon::QIcon ( )
noexcept

Constructs a null icon.

Definition at line 648 of file qicon.cpp.

Referenced by fromTheme().

+ Here is the caller graph for this function:

◆ QIcon() [2/6]

QIcon::QIcon ( const QPixmap pixmap)

Constructs an icon from a pixmap.

Definition at line 656 of file qicon.cpp.

References addPixmap(), and pixmap.

+ Here is the call graph for this function:

◆ QIcon() [3/6]

QIcon::QIcon ( const QIcon other)

Constructs a copy of other.

This is very fast.

Definition at line 665 of file qicon.cpp.

References QBasicAtomicInteger< T >::ref(), and QIconPrivate::ref.

+ Here is the call graph for this function:

◆ QIcon() [4/6]

QIcon::QIcon ( QIcon &&  other)
inlinenoexcept

Move-constructs a QIcon instance, making it point to the same object that other was pointing to.

Definition at line 28 of file qicon.h.

◆ QIcon() [5/6]

QIcon::QIcon ( const QString fileName)
explicit

Constructs an icon from the file with the given fileName.

The file will be loaded on demand.

If fileName contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.

The file name can refer to an actual file on disk or to one of the application's embedded resources. See the \l{resources.html}{Resource System} overview for details on how to embed images and other resource files in the application's executable.

Use the QImageReader::supportedImageFormats() and QImageWriter::supportedImageFormats() functions to retrieve a complete list of the supported file formats.

Definition at line 697 of file qicon.cpp.

References addFile(), and fileName.

+ Here is the call graph for this function:

◆ QIcon() [6/6]

QIcon::QIcon ( QIconEngine engine)
explicit

Creates an icon with a specific icon engine.

The icon takes ownership of the engine.

Definition at line 708 of file qicon.cpp.

◆ ~QIcon()

QIcon::~QIcon ( )

Destroys the icon.

Definition at line 716 of file qicon.cpp.

References QBasicAtomicInteger< T >::deref(), and QIconPrivate::ref.

+ Here is the call graph for this function:

Member Function Documentation

◆ actualSize()

QSize QIcon::actualSize ( const QSize size,
Mode  mode = Normal,
State  state = Off 
) const

Returns the actual size of the icon for the requested size, mode, and state.

The result might be smaller than requested, but never larger. The returned size is in device-independent pixels (This is relevant for high-dpi pixmaps.)

See also
pixmap(), paint()

Definition at line 880 of file qicon.cpp.

References actualSize(), QIconEngine::actualSize(), QIconPrivate::engine, QIconPrivate::pixmapDevicePixelRatio(), qApp, and state.

Referenced by actualSize(), QIconLoaderEngine::actualSize(), createHIcon(), QQC2::QWindowsXPStyle::drawControl(), QFontFamilyDelegate::paint(), QCommandLinkButton::paintEvent(), qt_aqua_get_known_size(), QItemDelegate::rect(), QWindowsSystemTrayIcon::showMessage(), QDockWidgetTitleButton::sizeHint(), QQC2_NAMESPACE::QMacStyle::subElementRect(), QQC2::QCommonStyle::subElementRect(), QMacStyle::subElementRect(), QCommonStyle::subElementRect(), QQC2::QMacStylePrivate::tabLayout(), and QQC2::QCommonStylePrivate::tabLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addFile()

void QIcon::addFile ( const QString fileName,
const QSize size = QSize(),
Mode  mode = Normal,
State  state = Off 
)

Adds an image from the file with the given fileName to the icon, as a specialization for size, mode and state.

The file will be loaded on demand. Note: custom icon engines are free to ignore additionally added pixmaps.

If fileName contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.

The file name can refer to an actual file on disk or to one of the application's embedded resources. See the \l{resources.html}{Resource System} overview for details on how to embed images and other resource files in the application's executable.

Use the QImageReader::supportedImageFormats() and QImageWriter::supportedImageFormats() functions to retrieve a complete list of the supported file formats.

If a high resolution version of the image exists (identified by the suffix @2x on the base name), it is automatically loaded and added with the {device pixel ratio} set to a value of 2. This can be disabled by setting the environment variable QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING (see QImageReader).

Note
When you add a non-empty filename to a QIcon, the icon becomes non-null, even if the file doesn't exist or points to a corrupt file.
See also
addPixmap(), QPixmap::devicePixelRatio()

Definition at line 1067 of file qicon.cpp.

References QIconEngine::addFile(), detach(), QIconPrivate::engine, engine, fileName, iconEngineFromSuffix(), info, QString::isEmpty(), QMimeDatabase::mimeTypeForFile(), QMimeType::preferredSuffix, qApp, qt_findAtNxFile(), state, and QFileInfo::suffix().

Referenced by QIcon(), qt_setupActionIcon(), QQC2::QCommonStyle::standardIcon(), and QCommonStyle::standardIcon().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addPixmap()

void QIcon::addPixmap ( const QPixmap pixmap,
Mode  mode = Normal,
State  state = Off 
)

Adds pixmap to the icon, as a specialization for mode and state.

Custom icon engines are free to ignore additionally added pixmaps.

See also
addFile()

Definition at line 1014 of file qicon.cpp.

References QIconEngine::addPixmap(), detach(), QIconPrivate::engine, pixmap, and state.

Referenced by QIcon(), QAbstractFileIconProviderPrivate::getPlatformThemeIcon(), QCss::Declaration::iconValue(), QQC2::QCommonStyle::standardIcon(), QCommonStyle::standardIcon(), and QWindowsVistaStyle::standardIcon().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ availableSizes()

QList< QSize > QIcon::availableSizes ( Mode  mode = Normal,
State  state = Off 
) const
Since
4.5

Returns a list of available icon sizes for the specified mode and state.

Definition at line 1098 of file qicon.cpp.

References QIconEngine::availableSizes(), QIconPrivate::engine, and state.

Referenced by QIconLoaderEngine::availableSizes(), availableXdgFileIconSizes(), fromTheme(), QXcbWindow::setWindowIcon(), QQC2::QCommonStyle::standardIcon(), QCommonStyle::standardIcon(), and QDBusTrayIcon::updateIcon().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cacheKey()

qint64 QIcon::cacheKey ( ) const

Returns a number that identifies the contents of this QIcon object.

Distinct QIcon objects can have the same key if they refer to the same contents.

Since
4.3

The cacheKey() will change when the icon is altered via addPixmap() or addFile().

Cache keys are mostly useful in conjunction with caching.

See also
QPixmap::cacheKey()

Definition at line 773 of file qicon.cpp.

References QIconPrivate::detach_no, and QIconPrivate::serialNum.

Referenced by QQC2::QWindowsXPStyle::drawControl(), QWindowsVistaStyle::drawControl(), QWindowsMenuItem::setIcon(), QMacStyle::subElementRect(), QCommonStyle::subElementRect(), and QWindowsSystemTrayIcon::updateIcon().

+ Here is the caller graph for this function:

◆ data_ptr()

DataPtr & QIcon::data_ptr ( )
inline

Definition at line 105 of file qicon.h.

References d.

Referenced by ScalableEntry::pixmap().

+ Here is the caller graph for this function:

◆ detach()

void QIcon::detach ( )

Definition at line 987 of file qicon.cpp.

References QIconEngine::clone(), QBasicAtomicInteger< T >::deref(), QIconPrivate::detach_no, QIconPrivate::engine, QIconEngine::isNull(), QBasicAtomicInteger< T >::loadRelaxed(), and QIconPrivate::ref.

Referenced by addFile(), addPixmap(), and setIsMask().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fallbackSearchPaths()

QStringList QIcon::fallbackSearchPaths ( )
static
Since
5.11

Returns the fallback search paths for icons.

The fallback search paths are used to look for standalone icon files if the \l{themeName()}{current icon theme} or \l{fallbackIconTheme()}{fallback icon theme} do not provide results for an icon lookup.

The default value will depend on the platform.

See also
setFallbackSearchPaths(), themeSearchPaths()

Definition at line 1168 of file qicon.cpp.

References QIconLoader::fallbackSearchPaths(), and QIconLoader::instance().

Referenced by src_gui_image_qicon::wrapper2().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fallbackThemeName()

QString QIcon::fallbackThemeName ( )
static
Since
5.12

Returns the name of the fallback icon theme.

On X11, if not set, the fallback icon theme depends on your desktop settings. On other platforms it is not set by default.

See also
setFallbackThemeName(), themeName()

Definition at line 1236 of file qicon.cpp.

References QIconLoader::fallbackThemeName(), and QIconLoader::instance().

+ Here is the call graph for this function:

◆ fromTheme() [1/2]

QIcon QIcon::fromTheme ( const QString name)
static
Since
4.6

Returns the QIcon corresponding to name in the current icon theme.

The latest version of the freedesktop icon specification and naming specification can be obtained here:

\list

To fetch an icon from the current icon theme:

QIcon undoicon = QIcon::fromTheme("edit-undo");
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
static QIcon fromTheme(const QString &name)
Definition qicon.cpp:1296
Note
By default, only X11 will support themed icons. In order to use themed icons on Mac and Windows, you will have to bundle a compliant theme in one of your themeSearchPaths() and set the appropriate themeName().
Qt will make use of GTK's icon-theme.cache if present to speed up the lookup. These caches can be generated using gtk-update-icon-cache: \l{https://developer.gnome.org/gtk3/stable/gtk-update-icon-cache.html}.
If an icon can't be found in the current theme, then it will be searched in fallbackSearchPaths() as an unthemed icon.
See also
themeName(), setThemeName(), themeSearchPaths(), fallbackSearchPaths()

Definition at line 1296 of file qicon.cpp.

References QIcon(), icon, and QDir::isAbsolutePath().

Referenced by availableXdgFileIconSizes(), QGuiApplicationPrivate::createPlatformIntegration(), fromTheme(), QAbstractFileIconProviderPrivate::getIconThemeIcon(), QAbstractFileIconProviderPrivate::getIconThemeIcon(), hasThemeIcon(), qt_setupActionIcon(), setActionIcon(), QQC2::QCommonStyle::standardIcon(), QCommonStyle::standardIcon(), QQC2::QCommonStyle::standardPixmap(), QCommonStyle::standardPixmap(), QQuickLabsPlatformIconLoader::toQIcon(), and src_gui_image_qicon::wrapper1().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromTheme() [2/2]

QIcon QIcon::fromTheme ( const QString name,
const QIcon fallback 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the QIcon corresponding to name in the current icon theme.

If no such icon is found in the current theme fallback is returned instead.

If you want to provide a guaranteed fallback for platforms that do not support theme icons, you can use the second argument:

QIcon undoicon = QIcon::fromTheme("edit-undo", QIcon(":/undo.png"));

Definition at line 1322 of file qicon.cpp.

References availableSizes(), fromTheme(), icon, QList< T >::isEmpty(), and isNull().

+ Here is the call graph for this function:

◆ hasThemeIcon()

bool QIcon::hasThemeIcon ( const QString name)
static
Since
4.6

Returns true if there is an icon available for name in the current icon theme, otherwise returns false.

See also
themeSearchPaths(), fromTheme(), setThemeName()

Definition at line 1340 of file qicon.cpp.

References fromTheme(), icon, and name().

+ Here is the call graph for this function:

◆ isDetached()

bool QIcon::isDetached ( ) const

Definition at line 980 of file qicon.cpp.

References QBasicAtomicInteger< T >::loadRelaxed(), and QIconPrivate::ref.

+ Here is the call graph for this function:

◆ isMask()

bool QIcon::isMask ( ) const
Since
5.6

Returns true if this icon has been marked as a mask image. Certain platforms render mask icons differently (for example, menu icons on \macos).

See also
setIsMask()

Definition at line 1371 of file qicon.cpp.

References QIconPrivate::is_mask.

Referenced by setIsMask().

+ Here is the caller graph for this function:

◆ isNull()

bool QIcon::isNull ( ) const

Returns true if the icon is empty; otherwise returns false.

An icon is empty if it has neither a pixmap nor a filename.

Note: Even a non-null icon might not be able to create valid pixmaps, eg. if the file does not exist or cannot be read.

Definition at line 973 of file qicon.cpp.

References QIconPrivate::engine, and QIconEngine::isNull().

Referenced by QDBusMenuItem::QDBusMenuItem(), QMenuBarPrivate::calcActionRects(), createHIcon(), QFileSystemModel::data(), QUndoModel::data(), QQC2_NAMESPACE::QMacStyle::drawControl(), QQC2::QCommonStyle::drawControl(), QMacStyle::drawControl(), QCommonStyle::drawControl(), QtAndroidMenu::fillMenuItem(), fromTheme(), QFileIconProviderPrivate::getIcon(), QFileIconProvider::icon(), iconToQXdgDBusImageVector(), QCss::Declaration::iconValue(), QHeaderView::initStyleOptionForIndex(), QComboBox::insertItem(), QQC2::QCommonStylePrivate::isViewItemCached(), QtWaylandClient::QWaylandBradientDecoration::paint(), ScalableEntry::pixmap(), qt_aqua_get_known_size(), QQC2_NAMESPACE::qt_aqua_get_known_size(), QHeaderView::sectionSizeFromContents(), setActionIcon(), QTabBar::setTabIcon(), QWindowPrivate::setVisible(), QWidget::setWindowIcon(), QCocoaWindow::setWindowIcon(), QXcbWindow::setWindowIcon(), QQC2::QCommonStyle::sizeFromContents(), QCheckBox::sizeHint(), QRadioButton::sizeHint(), QMessageBoxPrivate::standardIcon(), QQC2::QCommonStyle::standardIcon(), QCommonStyle::standardIcon(), QQC2::QCommonStyle::subElementRect(), QMacStyle::subElementRect(), QCommonStyle::subElementRect(), QQC2::QMacStylePrivate::tabLayout(), QQC2::QCommonStylePrivate::tabLayout(), QTabBar::tabSizeHint(), and QMenuPrivate::updateActionRects().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ name()

QString QIcon::name ( ) const
Since
4.7

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

Depending on the way the icon was created, it may have an associated name. This is the case for icons created with fromTheme().

See also
fromTheme(), QIconEngine::iconName()

Definition at line 1115 of file qicon.cpp.

References QIconPrivate::engine, and QIconEngine::iconName().

Referenced by QDBusMenuItem::QDBusMenuItem(), hasThemeIcon(), and QDBusTrayIcon::updateIcon().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator QVariant()

QIcon::operator QVariant ( ) const

Returns the icon as a QVariant.

Definition at line 755 of file qicon.cpp.

References QVariant::fromValue().

+ Here is the call graph for this function:

◆ operator!=()

bool QIcon::operator!= ( const QIcon ) const
delete

◆ operator=()

QIcon & QIcon::operator= ( const QIcon other)

Assigns the other icon to this icon and returns a reference to this icon.

Move-assigns other to this QIcon instance.

Since
5.2

Definition at line 726 of file qicon.cpp.

References QBasicAtomicInteger< T >::deref(), other(), and QIconPrivate::ref.

+ Here is the call graph for this function:

◆ operator==()

bool QIcon::operator== ( const QIcon ) const
delete

◆ paint() [1/2]

void QIcon::paint ( QPainter painter,
const QRect rect,
Qt::Alignment  alignment = Qt::AlignCenter,
Mode  mode = Normal,
State  state = Off 
) const

Uses the painter to paint the icon with specified alignment, required mode, and state into the rectangle rect.

See also
actualSize(), pixmap()

Definition at line 931 of file qicon.cpp.

References QIconEngine::actualSize(), Qt::AlignBottom, alignedRect(), Qt::AlignHCenter, alignment, Qt::AlignRight, Qt::AlignVCenter, QIconPrivate::engine, QPainter::layoutDirection(), QIconEngine::paint(), painter, rect, state, and QGuiApplicationPrivate::visualAlignment().

Referenced by QtWaylandClient::QWaylandBradientDecoration::paint(), and QFontFamilyDelegate::paint().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ paint() [2/2]

void QIcon::paint ( QPainter painter,
int  x,
int  y,
int  w,
int  h,
Qt::Alignment  alignment = Qt::AlignCenter,
Mode  mode = Normal,
State  state = Off 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Paints the icon into the rectangle QRect(x, y, w, h).

Definition at line 63 of file qicon.h.

References alignment, paint, painter, and state.

◆ pixmap() [1/4]

QPixmap QIcon::pixmap ( const QSize size,
Mode  mode = Normal,
State  state = Off 
) const

Returns a pixmap with the requested size, mode, and state, generating one if necessary.

The pixmap might be smaller than requested, but never larger, unless the device-pixel ratio of the returned pixmap is larger than 1.

See also
actualSize(), paint()

Definition at line 788 of file qicon.cpp.

References dpr(), pixmap, and state.

Referenced by QDBusMenuItem::QDBusMenuItem(), createHIcon(), QQC2::QCommonStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QQC2::QWindowsXPStyle::drawComplexControl(), QQC2_NAMESPACE::QMacStyle::drawControl(), QQC2::QCommonStyle::drawControl(), QMacStyle::drawControl(), QCommonStyle::drawControl(), QQC2::QWindowsXPStyle::drawControl(), QWindowsVistaStyle::drawControl(), src_gui_image_qicon::MyWidget::drawIcon(), QtAndroidMenu::fillMenuItem(), if(), QWasmWindow::setWindowIcon(), QXcbWindow::setWindowIcon(), QWindowsSystemTrayIcon::showMessage(), QMessageBoxPrivate::standardIcon(), QQC2::QCommonStyle::standardIcon(), QCommonStyle::standardIcon(), QQC2_NAMESPACE::QMacStyle::standardPixmap(), QMacStyle::standardPixmap(), QQC2::QCommonStyle::standardPixmap(), QCommonStyle::standardPixmap(), QQC2::QWindowsXPStyle::standardPixmap(), QWindowsVistaStyle::standardPixmap(), QQC2::QCommonStyle::subElementRect(), and QCommonStyle::subElementRect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pixmap() [2/4]

QPixmap QIcon::pixmap ( const QSize size,
qreal  devicePixelRatio,
Mode  mode = Normal,
State  state = Off 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
6.0

Returns a pixmap with the requested size, devicePixelRatio, mode, and state, generating one if necessary.

See also
actualSize(), paint()

Definition at line 825 of file qicon.cpp.

References QIconPrivate::engine, QIconEngine::pixmap(), pixmap, QIconPrivate::pixmapDevicePixelRatio(), qApp, QIconEngine::scaledPixmap(), and state.

+ Here is the call graph for this function:

◆ pixmap() [3/4]

QPixmap QIcon::pixmap ( int  extent,
Mode  mode = Normal,
State  state = Off 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a pixmap of size QSize(extent, extent).

The pixmap might be smaller than requested, but never larger, unless the device-pixel ratio of the returned pixmap is larger than 1.

Definition at line 46 of file qicon.h.

References pixmap, and state.

◆ pixmap() [4/4]

QPixmap QIcon::pixmap ( int  w,
int  h,
Mode  mode = Normal,
State  state = Off 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a pixmap of size QSize(w, h).

The pixmap might be smaller than requested, but never larger, unless the device-pixel ratio of the returned pixmap is larger than 1.

Definition at line 44 of file qicon.h.

References pixmap, and state.

◆ setFallbackSearchPaths()

void QIcon::setFallbackSearchPaths ( const QStringList paths)
static
Since
5.11

Sets the fallback search paths for icons to paths.

The fallback search paths are used to look for standalone icon files if the \l{themeName()}{current icon theme} or \l{fallbackIconTheme()}{fallback icon theme} do not provide results for an icon lookup.

Note
To add some path without replacing existing ones:
static void setFallbackSearchPaths(const QStringList &paths)
Definition qicon.cpp:1189
static QStringList fallbackSearchPaths()
Definition qicon.cpp:1168
See also
fallbackSearchPaths(), setThemeSearchPaths()

Definition at line 1189 of file qicon.cpp.

References QIconLoader::instance(), and QIconLoader::setFallbackSearchPaths().

Referenced by src_gui_image_qicon::wrapper2().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFallbackThemeName()

void QIcon::setFallbackThemeName ( const QString name)
static
Since
5.12

Sets the fallback icon theme to name.

The fallback icon theme is used for last resort lookup of icons not provided by the \l{themeName()}{current icon theme}, or if the \l{themeName()}{current icon theme} does not exist.

The name should correspond to a directory name in the themeSearchPath() containing an index.theme file describing its contents.

Note
This should be done before creating \l QGuiApplication, to ensure correct initialization.
See also
fallbackThemeName(), themeSearchPaths(), themeName()

Definition at line 1259 of file qicon.cpp.

References QIconLoader::instance(), and QIconLoader::setFallbackThemeName().

+ Here is the call graph for this function:

◆ setIsMask()

void QIcon::setIsMask ( bool  isMask)
Since
5.6

Indicate that this icon is a mask image(boolean isMask), and hence can potentially be modified based on where it's displayed.

See also
isMask()

Definition at line 1354 of file qicon.cpp.

References detach(), QIconPrivate::is_mask, and isMask().

+ Here is the call graph for this function:

◆ setThemeName()

void QIcon::setThemeName ( const QString name)
static
Since
4.6

Sets the current icon theme to name.

The name should correspond to a directory name in the themeSearchPath() containing an index.theme file describing its contents.

See also
themeSearchPaths(), themeName()

Definition at line 1205 of file qicon.cpp.

References QIconLoader::instance(), and QIconLoader::setThemeName().

+ Here is the call graph for this function:

◆ setThemeSearchPaths()

void QIcon::setThemeSearchPaths ( const QStringList paths)
static
Since
4.6

Sets the search paths for icon themes to paths.

See also
themeSearchPaths(), fromTheme(), setThemeName()

Definition at line 1128 of file qicon.cpp.

References QIconLoader::instance(), and QIconLoader::setThemeSearchPath().

+ Here is the call graph for this function:

◆ swap()

void QIcon::swap ( QIcon other)
inlinenoexcept
Since
4.8

Swaps icon other with this icon. This operation is very fast and never fails.

Definition at line 36 of file qicon.h.

References d, other(), and qt_ptr_swap().

+ Here is the call graph for this function:

◆ themeName()

QString QIcon::themeName ( )
static
Since
4.6

Returns the name of the current icon theme.

On X11, the current icon theme depends on your desktop settings. On other platforms it is not set by default.

See also
setThemeName(), themeSearchPaths(), fromTheme(), hasThemeIcon()

Definition at line 1221 of file qicon.cpp.

References QIconLoader::instance(), and QIconLoader::themeName().

Referenced by QQC2::QCommonStyle::standardIcon(), QCommonStyle::standardIcon(), QQC2::QCommonStyle::standardPixmap(), and QCommonStyle::standardPixmap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ themeSearchPaths()

QStringList QIcon::themeSearchPaths ( )
static
Since
4.6

Returns the search paths for icon themes.

The default value will depend on the platform:

On X11, the search path will use the XDG_DATA_DIRS environment variable if available.

By default all platforms will have the resource directory {:\icons} as a fallback. You can use "rcc -project" to generate a resource file from your icon theme.

See also
setThemeSearchPaths(), fromTheme(), setThemeName()

Definition at line 1149 of file qicon.cpp.

References QIconLoader::instance(), and QIconLoader::themeSearchPaths().

Referenced by QIconTheme::QIconTheme().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator<< [1/2]

QDataStream & operator<< ( QDataStream stream,
const QIcon icon 
)
friend
Since
4.2

Writes the given icon to the given stream as a PNG image. If the icon contains more than one image, all images will be written to the stream. Note that writing the stream to a file will not produce a valid image file.

Definition at line 1393 of file qicon.cpp.

◆ operator<<() [2/2]

QDataStream & operator<< ( QDataStream stream,
const QIcon icon 
)
related
Since
4.2

Writes the given icon to the given stream as a PNG image. If the icon contains more than one image, all images will be written to the stream. Note that writing the stream to a file will not produce a valid image file.

Definition at line 1393 of file qicon.cpp.

◆ operator>> [1/2]

QDataStream & operator>> ( QDataStream stream,
QIcon icon 
)
friend
Since
4.2

Reads an image, or a set of images, from the given stream into the given icon.

Definition at line 1432 of file qicon.cpp.

◆ operator>>() [2/2]

QDataStream & operator>> ( QDataStream stream,
QIcon icon 
)
related
Since
4.2

Reads an image, or a set of images, from the given stream into the given icon.

Definition at line 1432 of file qicon.cpp.


The documentation for this class was generated from the following files: