Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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...
 
enum class  ThemeIcon {
  AddressBookNew , ApplicationExit , AppointmentNew , CallStart ,
  CallStop , ContactNew , DocumentNew , DocumentOpen ,
  DocumentOpenRecent , DocumentPageSetup , DocumentPrint , DocumentPrintPreview ,
  DocumentProperties , DocumentRevert , DocumentSave , DocumentSaveAs ,
  DocumentSend , EditClear , EditCopy , EditCut ,
  EditDelete , EditFind , EditPaste , EditRedo ,
  EditSelectAll , EditUndo , FolderNew , FormatIndentLess ,
  FormatIndentMore , FormatJustifyCenter , FormatJustifyFill , FormatJustifyLeft ,
  FormatJustifyRight , FormatTextDirectionLtr , FormatTextDirectionRtl , FormatTextBold ,
  FormatTextItalic , FormatTextUnderline , FormatTextStrikethrough , GoDown ,
  GoHome , GoNext , GoPrevious , GoUp ,
  HelpAbout , HelpFaq , InsertImage , InsertLink ,
  InsertText , ListAdd , ListRemove , MailForward ,
  MailMarkImportant , MailMarkRead , MailMarkUnread , MailMessageNew ,
  MailReplyAll , MailReplySender , MailSend , MediaEject ,
  MediaPlaybackPause , MediaPlaybackStart , MediaPlaybackStop , MediaRecord ,
  MediaSeekBackward , MediaSeekForward , MediaSkipBackward , MediaSkipForward ,
  ObjectRotateLeft , ObjectRotateRight , ProcessStop , SystemLockScreen ,
  SystemLogOut , SystemSearch , SystemReboot , SystemShutdown ,
  ToolsCheckSpelling , ViewFullscreen , ViewRefresh , ViewRestore ,
  WindowClose , WindowNew , ZoomFitBest , ZoomIn ,
  ZoomOut , AudioCard , AudioInputMicrophone , Battery ,
  CameraPhoto , CameraVideo , CameraWeb , Computer ,
  DriveHarddisk , DriveOptical , InputGaming , InputKeyboard ,
  InputMouse , InputTablet , MediaFlash , MediaOptical ,
  MediaTape , MultimediaPlayer , NetworkWired , NetworkWireless ,
  Phone , Printer , Scanner , VideoDisplay ,
  AppointmentMissed , AppointmentSoon , AudioVolumeHigh , AudioVolumeLow ,
  AudioVolumeMedium , AudioVolumeMuted , BatteryCaution , BatteryLow ,
  DialogError , DialogInformation , DialogPassword , DialogQuestion ,
  DialogWarning , FolderDragAccept , FolderOpen , FolderVisiting ,
  ImageLoading , ImageMissing , MailAttachment , MailUnread ,
  MailRead , MailReplied , MediaPlaylistRepeat , MediaPlaylistShuffle ,
  NetworkOffline , PrinterPrinting , SecurityHigh , SecurityLow ,
  SoftwareUpdateAvailable , SoftwareUpdateUrgent , SyncError , SyncSynchronizing ,
  UserAvailable , UserOffline , WeatherClear , WeatherClearNight ,
  WeatherFewClouds , WeatherFewCloudsNight , WeatherFog , WeatherShowers ,
  WeatherSnow , WeatherStorm , NThemeIcons
}
 
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 \l{themeName()}{current icon theme}.
 
static bool hasThemeIcon (const QString &name)
 
static QIcon fromTheme (ThemeIcon icon)
 
static QIcon fromTheme (ThemeIcon icon, const QIcon &fallback)
 
static bool hasThemeIcon (ThemeIcon icon)
 
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 UI components to show an icon representing a particular action.

Definition at line 19 of file qicon.h.

Member Typedef Documentation

◆ DataPtr

Definition at line 265 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.

◆ ThemeIcon

enum class QIcon::ThemeIcon
strong
Since
6.7

This enum provides access to icons that are provided by most icon theme implementations.

\value AddressBookNew The icon for the action to create a new address book. \value ApplicationExit The icon for exiting an application. \value AppointmentNew The icon for the action to create a new appointment. \value CallStart The icon for initiating or accepting a call. \value CallStop The icon for stopping a current call. \value ContactNew The icon for the action to create a new contact. \value DocumentNew The icon for the action to create a new document. \value DocumentOpen The icon for the action to open a document. \value DocumentOpenRecent The icon for the action to open a document that was recently opened. \value DocumentPageSetup The icon for the {page setup} action. \value DocumentPrint The icon for the {print} action. \value DocumentPrintPreview The icon for the {print preview} action. \value DocumentProperties The icon for the action to view the properties of a document. \value DocumentRevert The icon for the action of reverting to a previous version of a document. \value DocumentSave The icon for the {save} action. \value DocumentSaveAs The icon for the {save as} action. \value DocumentSend The icon for the {send} action. \value EditClear The icon for the {clear} action. \value EditCopy The icon for the {copy} action. \value EditCut The icon for the {cut} action. \value EditDelete The icon for the {delete} action. \value EditFind The icon for the {find} action. \value EditPaste The icon for the {paste} action. \value EditRedo The icon for the {redo} action. \value EditSelectAll The icon for the {select all} action. \value EditUndo The icon for the {undo} action. \value FolderNew The icon for creating a new folder. \value FormatIndentLess The icon for the {decrease indent formatting} action. \value FormatIndentMore The icon for the {increase indent formatting} action. \value FormatJustifyCenter The icon for the {center justification formatting} action. \value FormatJustifyFill The icon for the {fill justification formatting} action. \value FormatJustifyLeft The icon for the {left justification formatting} action. \value FormatJustifyRight The icon for the {right justification} action. \value FormatTextDirectionLtr The icon for the {left-to-right text formatting} action. \value FormatTextDirectionRtl The icon for the {right-to-left formatting} action. \value FormatTextBold The icon for the {bold text formatting} action. \value FormatTextItalic The icon for the {italic text formatting} action. \value FormatTextUnderline The icon for the {underlined text formatting} action. \value FormatTextStrikethrough The icon for the {strikethrough text formatting} action. \value GoDown The icon for the {go down in a list} action. \value GoHome The icon for the {go to home location} action. \value GoNext The icon for the {go to the next item in a list} action. \value GoPrevious The icon for the {go to the previous item in a list} action. \value GoUp The icon for the {go up in a list} action. \value HelpAbout The icon for the {About} item in the Help menu. \value HelpFaq The icon for the {FAQ} item in the Help menu. \value InsertImage The icon for the {insert image} action of an application. \value InsertLink The icon for the {insert link} action of an application. \value InsertText The icon for the {insert text} action of an application. \value ListAdd The icon for the {add to list} action. \value ListRemove The icon for the {remove from list} action. \value MailForward The icon for the {forward} action. \value MailMarkImportant The icon for the {mark as important} action. \value MailMarkRead The icon for the {mark as read} action. \value MailMarkUnread The icon for the {mark as unread} action. \value MailMessageNew The icon for the {compose new mail} action. \value MailReplyAll The icon for the {reply to all} action. \value MailReplySender The icon for the {reply to sender} action. \value MailSend The icon for the {send} action. \value MediaEject The icon for the {eject} action of a media player or file manager. \value MediaPlaybackPause The icon for the {pause} action of a media player. \value MediaPlaybackStart The icon for the {start playback} action of a media player. \value MediaPlaybackStop The icon for the {stop} action of a media player. \value MediaRecord The icon for the {record} action of a media application. \value MediaSeekBackward The icon for the {seek backward} action of a media player. \value MediaSeekForward The icon for the {seek forward} action of a media player. \value MediaSkipBackward The icon for the {skip backward} action of a media player. \value MediaSkipForward The icon for the {skip forward} action of a media player. \value ObjectRotateLeft The icon for the {rotate left} action performed on an object. \value ObjectRotateRight The icon for the {rotate right} action performed on an object. \value ProcessStop The icon for the {stop action in applications with} actions that may take a while to process, such as web page loading in a browser. \value SystemLockScreen The icon for the {lock screen} action. \value SystemLogOut The icon for the {log out} action. \value SystemSearch The icon for the {search} action. \value SystemReboot The icon for the {reboot} action. \value SystemShutdown The icon for the {shutdown} action. \value ToolsCheckSpelling The icon for the {check spelling} action. \value ViewFullscreen The icon for the {fullscreen} action. \value ViewRefresh The icon for the {refresh} action. \value ViewRestore The icon for leaving the fullscreen view. \value WindowClose The icon for the {close window} action. \value WindowNew The icon for the {new window} action. \value ZoomFitBest The icon for the {best fit} action. \value ZoomIn The icon for the {zoom in} action. \value ZoomOut The icon for the {zoom out} action.

\value AudioCard The icon for the audio rendering device. \value AudioInputMicrophone The icon for the microphone audio input device. \value Battery The icon for the system battery device. \value CameraPhoto The icon for a digital still camera devices. \value CameraVideo The icon for a video camera device. \value CameraWeb The icon for a web camera device. \value Computer The icon for the computing device as a whole. \value DriveHarddisk The icon for hard disk drives. \value DriveOptical The icon for optical media drives such as CD and DVD. \value InputGaming The icon for the gaming input device. \value InputKeyboard The icon for the keyboard input device. \value InputMouse The icon for the mousing input device. \value InputTablet The icon for graphics tablet input devices. \value MediaFlash The icon for flash media, such as a memory stick. \value MediaOptical The icon for physical optical media such as CD and DVD. \value MediaTape The icon for generic physical tape media. \value MultimediaPlayer The icon for generic multimedia playing devices. \value NetworkWired The icon for wired network connections. \value NetworkWireless The icon for wireless network connections. \value Phone The icon for phone devices. \value Printer The icon for a printer device. \value Scanner The icon for a scanner device. \value VideoDisplay The icon for the monitor that video gets displayed on.

\value AppointmentMissed The icon for when an appointment was missed. \value AppointmentSoon The icon for when an appointment will occur soon. \value AudioVolumeHigh The icon used to indicate high audio volume. \value AudioVolumeLow The icon used to indicate low audio volume. \value AudioVolumeMedium The icon used to indicate medium audio volume. \value AudioVolumeMuted The icon used to indicate the muted state for audio playback. \value BatteryCaution The icon used when the battery is below 40%. \value BatteryLow The icon used when the battery is below 20%. \value DialogError The icon used when a dialog is opened to explain an error condition to the user. \value DialogInformation The icon used when a dialog is opened to give information to the user that may be pertinent to the requested action. \value DialogPassword The icon used when a dialog requesting the authentication credentials for a user is opened. \value DialogQuestion The icon used when a dialog is opened to ask a simple question to the user. \value DialogWarning The icon used when a dialog is opened to warn the user of impending issues with the requested action. \value FolderDragAccept The icon used for a folder while an acceptable object is being dragged onto it. \value FolderOpen The icon used for folders, while their contents are being displayed within the same window. \value FolderVisiting The icon used for folders, while their contents are being displayed in another window. \value ImageLoading The icon used while another image is being loaded. \value ImageMissing The icon used when another image could not be loaded. \value MailAttachment The icon for a message that contains attachments. \value MailUnread The icon for an unread message. \value MailRead The icon for a read message. \value MailReplied The icon for a message that has been replied to. \value MediaPlaylistRepeat The icon for the repeat mode of a media player. \value MediaPlaylistShuffle The icon for the shuffle mode of a media player. \value NetworkOffline The icon used to indicate that the device is not connected to the network. \value PrinterPrinting The icon used while a print job is successfully being spooled to a printing device. \value SecurityHigh The icon used to indicate that the security level of an item is known to be high. \value SecurityLow The icon used to indicate that the security level of an item is known to be low. \value SoftwareUpdateAvailable The icon used to indicate that an update is available. \value SoftwareUpdateUrgent The icon used to indicate that an urgent update is available. \value SyncError The icon used when an error occurs while attempting to synchronize data across devices. \value SyncSynchronizing The icon used while data is successfully synchronizing across devices. \value UserAvailable The icon used to indicate that a user is available. \value UserOffline The icon used to indicate that a user is not available. \value WeatherClear The icon used to indicate that the sky is clear. \value WeatherClearNight The icon used to indicate that the sky is clear during the night. \value WeatherFewClouds The icon used to indicate that the sky is partly cloudy. \value WeatherFewCloudsNight The icon used to indicate that the sky is partly cloudy during the night. \value WeatherFog The icon used to indicate that the weather is foggy. \value WeatherShowers The icon used to indicate that rain showers are occurring. \value WeatherSnow The icon used to indicate that snow is falling. \value WeatherStorm The icon used to indicate that the weather is stormy.

\omitvalue NThemeIcons

See also
{QIcon::Creating an icon from a theme or icon library}, fromTheme()
Enumerator
AddressBookNew 
ApplicationExit 
AppointmentNew 
CallStart 
CallStop 
ContactNew 
DocumentNew 
DocumentOpen 
DocumentOpenRecent 
DocumentPageSetup 
DocumentPrint 
DocumentPrintPreview 
DocumentProperties 
DocumentRevert 
DocumentSave 
DocumentSaveAs 
DocumentSend 
EditClear 
EditCopy 
EditCut 
EditDelete 
EditFind 
EditPaste 
EditRedo 
EditSelectAll 
EditUndo 
FolderNew 
FormatIndentLess 
FormatIndentMore 
FormatJustifyCenter 
FormatJustifyFill 
FormatJustifyLeft 
FormatJustifyRight 
FormatTextDirectionLtr 
FormatTextDirectionRtl 
FormatTextBold 
FormatTextItalic 
FormatTextUnderline 
FormatTextStrikethrough 
GoDown 
GoHome 
GoNext 
GoPrevious 
GoUp 
HelpAbout 
HelpFaq 
InsertImage 
InsertLink 
InsertText 
ListAdd 
ListRemove 
MailForward 
MailMarkImportant 
MailMarkRead 
MailMarkUnread 
MailMessageNew 
MailReplyAll 
MailReplySender 
MailSend 
MediaEject 
MediaPlaybackPause 
MediaPlaybackStart 
MediaPlaybackStop 
MediaRecord 
MediaSeekBackward 
MediaSeekForward 
MediaSkipBackward 
MediaSkipForward 
ObjectRotateLeft 
ObjectRotateRight 
ProcessStop 
SystemLockScreen 
SystemLogOut 
SystemSearch 
SystemReboot 
SystemShutdown 
ToolsCheckSpelling 
ViewFullscreen 
ViewRefresh 
ViewRestore 
WindowClose 
WindowNew 
ZoomFitBest 
ZoomIn 
ZoomOut 
AudioCard 
AudioInputMicrophone 
Battery 
CameraPhoto 
CameraVideo 
CameraWeb 
Computer 
DriveHarddisk 
DriveOptical 
InputGaming 
InputKeyboard 
InputMouse 
InputTablet 
MediaFlash 
MediaOptical 
MediaTape 
MultimediaPlayer 
NetworkWired 
NetworkWireless 
Phone 
Printer 
Scanner 
VideoDisplay 
AppointmentMissed 
AppointmentSoon 
AudioVolumeHigh 
AudioVolumeLow 
AudioVolumeMedium 
AudioVolumeMuted 
BatteryCaution 
BatteryLow 
DialogError 
DialogInformation 
DialogPassword 
DialogQuestion 
DialogWarning 
FolderDragAccept 
FolderOpen 
FolderVisiting 
ImageLoading 
ImageMissing 
MailAttachment 
MailUnread 
MailRead 
MailReplied 
MediaPlaylistRepeat 
MediaPlaylistShuffle 
NetworkOffline 
PrinterPrinting 
SecurityHigh 
SecurityLow 
SoftwareUpdateAvailable 
SoftwareUpdateUrgent 
SyncError 
SyncSynchronizing 
UserAvailable 
UserOffline 
WeatherClear 
WeatherClearNight 
WeatherFewClouds 
WeatherFewCloudsNight 
WeatherFog 
WeatherShowers 
WeatherSnow 
WeatherStorm 
NThemeIcons 

Definition at line 25 of file qicon.h.

Constructor & Destructor Documentation

◆ QIcon() [1/6]

QIcon::QIcon ( )
noexcept

Constructs a null icon.

Definition at line 692 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 700 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 709 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 185 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 741 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 752 of file qicon.cpp.

◆ ~QIcon()

QIcon::~QIcon ( )

Destroys the icon.

Definition at line 760 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 924 of file qicon.cpp.

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

Referenced by actualSize(), QIconLoaderEngine::actualSize(), createHIcon(), QFontFamilyDelegate::paint(), QCommandLinkButton::paintEvent(), QItemDelegate::rect(), QWindowsSystemTrayIcon::showMessage(), QDockWidgetTitleButton::sizeHint(), 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 1111 of file qicon.cpp.

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

Referenced by QIcon(), QCommonStylePrivate::iconFromMacTheme(), QCommonStylePrivate::iconFromResourceTheme(), qt_setupActionIcon(), and QQC2::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 1058 of file qicon.cpp.

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

Referenced by QIcon(), QAbstractFileIconProviderPrivate::getPlatformThemeIcon(), QCommonStylePrivate::iconFromApplicationTheme(), QCommonStylePrivate::iconFromMacTheme(), QCommonStylePrivate::iconFromResourceTheme(), QCommonStylePrivate::iconFromWindowsTheme(), QCss::Declaration::iconValue(), QQC2::QCommonStyle::standardIcon(), and QCommonStyle::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 1142 of file qicon.cpp.

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

Referenced by QIconLoaderEngine::availableSizes(), fromTheme(), QXcbWindow::setWindowIcon(), 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 817 of file qicon.cpp.

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

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

+ Here is the caller graph for this function:

◆ data_ptr()

DataPtr & QIcon::data_ptr ( )
inline

Definition at line 266 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 1031 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 consulted for standalone icon files if the \l{themeName()}{current icon theme} or \l{fallbackThemeName()}{fallback icon theme} do not provide results for an icon lookup.

If not set, the fallback search paths will be defined by the platform.

See also
setFallbackSearchPaths(), themeSearchPaths()

Definition at line 1211 of file qicon.cpp.

References 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.

If not set, the fallback icon theme will be defined by the platform.

Note
Platform fallback icon themes are only implemented on \l{Freedesktop} based systems at the moment, and the icon theme depends on your desktop settings.
See also
setFallbackThemeName(), themeName()

Definition at line 1291 of file qicon.cpp.

References QIconLoader::instance().

Referenced by QtWaylandClient::getIconSvg().

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

◆ fromTheme() [1/4]

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

Returns the QIcon corresponding to name in the \l{themeName()}{current icon theme}.

If the current theme does not provide an icon for name, the \l{fallbackThemeName()}{fallback icon theme} is consulted, before falling back to looking up standalone icon files in the \l{QIcon::fallbackSearchPaths()}{fallback icon search path}. Finally, the platform's native icon library is consulted.

To fetch an icon from the current icon theme:

If an \l{themeName()}{icon theme} has not been explicitly set via setThemeName() a platform defined icon theme will be used.

See also
themeName(), fallbackThemeName(), setThemeName(), themeSearchPaths(), fallbackSearchPaths(), {Freedesktop Icon Naming Specification}

Definition at line 1342 of file qicon.cpp.

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

Referenced by availableXdgFileIconSizes(), QGuiApplicationPrivate::createPlatformIntegration(), fromTheme(), fromTheme(), fromTheme(), QAbstractFileIconProviderPrivate::getIconThemeIcon(), QAbstractFileIconProviderPrivate::getIconThemeIcon(), hasThemeIcon(), QCommonStylePrivate::iconFromApplicationTheme(), qt_setupActionIcon(), QtWaylandClient::renderButtonIcon(), setActionIcon(), QQC2::QCommonStyle::standardIcon(), QQC2::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/4]

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 \l{themeName()}{current icon theme}.

If the current theme does not provide an icon for name, the \l{fallbackThemeName()}{fallback icon theme} is consulted, before falling back to looking up standalone icon files in the \l{QIcon::fallbackSearchPaths()}{fallback icon search path}. Finally, the platform's native icon library is consulted.

If no icon is found fallback is returned.

This is useful to provide a guaranteed fallback, regardless of whether the current set of icon themes and fallbacks paths support the requested icon.

For example:

See also
fallbackThemeName(), fallbackSearchPaths()

Definition at line 1380 of file qicon.cpp.

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

+ Here is the call graph for this function:

◆ fromTheme() [3/4]

QIcon QIcon::fromTheme ( QIcon::ThemeIcon icon)
static

Definition at line 1791 of file qicon.cpp.

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

+ Here is the call graph for this function:

◆ fromTheme() [4/4]

QIcon QIcon::fromTheme ( QIcon::ThemeIcon icon,
const QIcon & fallback )
static
Since
6.7 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 icon in the \l{themeName()}{current icon theme}.

If the current theme does not provide an icon for icon, the \l{fallbackThemeName()}{fallback icon theme} is consulted, before falling back to looking up standalone icon files in the \l{QIcon::fallbackSearchPaths()}{fallback icon search path}. Finally, the platform's native icon library is consulted.

If no icon is found and a fallback is provided, fallback is returned. This is useful to provide a guaranteed fallback, regardless of whether the current set of icon themes and fallbacks paths support the requested icon.

If no icon is found and no fallback is provided, a default constructed, empty QIcon is returned.

Definition at line 1796 of file qicon.cpp.

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

+ Here is the call graph for this function:

◆ hasThemeIcon() [1/2]

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 or any of the fallbacks, as described by fromTheme(), otherwise returns false.

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

Definition at line 1399 of file qicon.cpp.

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

Referenced by hasThemeIcon(), and QCommonStylePrivate::iconFromApplicationTheme().

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

◆ hasThemeIcon() [2/2]

bool QIcon::hasThemeIcon ( QIcon::ThemeIcon icon)
static
Since
6.7 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns true if there is an icon available for icon in the current icon theme or any of the fallbacks, as described by fromTheme(), otherwise returns false.

See also
fromTheme()

Definition at line 1763 of file qicon.cpp.

References hasThemeIcon(), icon, and themeIconName().

+ Here is the call graph for this function:

◆ isDetached()

bool QIcon::isDetached ( ) const

Definition at line 1024 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 1825 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 1017 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(), QWindows11Style::drawControl(), QtAndroidMenu::fillMenuItem(), fromTheme(), QFileIconProviderPrivate::getIcon(), QAbstractFileIconProvider::icon(), QAbstractFileIconProvider::icon(), iconToQXdgDBusImageVector(), QCss::Declaration::iconValue(), QHeaderView::initStyleOptionForIndex(), QComboBox::insertItem(), QtWaylandClient::QWaylandBradientDecoration::paint(), ScalableEntry::pixmap(), qt_aqua_get_known_size(), QQC2_NAMESPACE::qt_aqua_get_known_size(), QHeaderView::sectionSizeFromContents(), setActionIcon(), QTabBar::setTabIcon(), QWidget::setWindowIcon(), QCocoaWindow::setWindowIcon(), QXcbWindow::setWindowIcon(), QQC2::QCommonStyle::sizeFromContents(), QCheckBox::sizeHint(), QRadioButton::sizeHint(), QQC2::QCommonStyle::standardIcon(), QCommonStyle::standardIcon(), QCommonStyle::standardPixmap(), 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 1159 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 799 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 770 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 975 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 src_gui_image_qicon::MyWidget::drawIcon(), 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 220 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 832 of file qicon.cpp.

References dpr(), pixmap, and state.

Referenced by QDBusMenuItem::QDBusMenuItem(), QErrorMessage::QErrorMessage(), createHIcon(), QQC2_NAMESPACE::QMacStyle::drawControl(), QQC2::QCommonStyle::drawControl(), QMacStyle::drawControl(), QCommonStyle::drawControl(), QWindows11Style::drawControl(), QtAndroidMenu::fillMenuItem(), if(), QWasmWindow::setWindowIcon(), QXcbWindow::setWindowIcon(), QWindowsSystemTrayIcon::showMessage(), QQC2_NAMESPACE::QMacStyle::standardPixmap(), QMacStyle::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 869 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 203 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 201 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 consulted for standalone icon files if the \l{themeName()}{current icon theme} or \l{fallbackThemeName()}{fallback icon theme} do not provide results for an icon lookup.

For example:

See also
fallbackSearchPaths(), setThemeSearchPaths()

Definition at line 1232 of file qicon.cpp.

References 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:

◆ setFallbackThemeName()

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

Sets the fallback icon theme to name.

The fallback icon theme is consulted for 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 theme in the same format as documented by setThemeName(), and will be looked up in themeSearchPaths().

Note
Fallback icon themes should be set before creating QGuiApplication, to ensure correct initialization.
See also
fallbackThemeName(), themeSearchPaths(), themeName()

Definition at line 1314 of file qicon.cpp.

References QIconLoader::instance().

+ 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 1808 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 theme will be will be looked up in themeSearchPaths().

At the moment the only supported icon theme format is the \l{Freedesktop Icon Theme Specification}. The name should correspond to a directory name in the themeSearchPath() containing an index.theme file describing its contents.

See also
themeSearchPaths(), themeName(), {Freedesktop Icon Theme Specification}

Definition at line 1252 of file qicon.cpp.

References QIconLoader::instance().

+ 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.

The content of paths should follow the theme format documented by setThemeName().

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

Definition at line 1176 of file qicon.cpp.

References QIconLoader::instance().

+ 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 193 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.

If not set, the current icon theme will be defined by the platform.

Note
Platform icon themes are only implemented on \l{Freedesktop} based systems at the moment, and the icon theme depends on your desktop settings.
See also
setThemeName(), themeSearchPaths(), fromTheme(), hasThemeIcon()

Definition at line 1272 of file qicon.cpp.

References QIconLoader::instance().

Referenced by QtWaylandClient::getIconSvg(), QCommonStylePrivate::iconFromApplicationTheme(), QQC2::QCommonStyle::standardIcon(), and QQC2::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 search paths will be defined by the platform. All platforms will also have the resource directory {:\icons} as a fallback.

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

Definition at line 1191 of file qicon.cpp.

References QIconLoader::instance().

Referenced by QIconTheme::QIconTheme(), and QtWaylandClient::getIconSvg().

+ 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 1847 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 1847 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 1886 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 1886 of file qicon.cpp.


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