![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QIcon class provides scalable icons in different modes and states. More...
#include <qicon.h>
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. | |
QIcon & | operator= (const QIcon &other) |
Assigns the other icon to this icon and returns a reference to this icon. | |
void | swap (QIcon &other) noexcept |
\memberswap{icon} | |
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 |
Returns the name used to create the icon, if available. | |
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< QSize > | availableSizes (Mode mode=Normal, State state=Off) const |
Returns a list of available icon sizes for the specified mode and state. | |
void | setIsMask (bool isMask) |
bool | isMask () const |
DataPtr & | data_ptr () |
Static Public Member Functions | |
static QIcon | fromTheme (const QString &name) |
Returns the QIcon corresponding to name in the \l{themeName()}{current icon theme}. | |
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) |
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 . | |
static QIcon | fromTheme (ThemeIcon icon) |
static QIcon | fromTheme (ThemeIcon icon, const QIcon &fallback) |
static bool | hasThemeIcon (ThemeIcon icon) |
static QStringList | themeSearchPaths () |
Returns the search paths for icon themes. | |
static void | setThemeSearchPaths (const QStringList &searchpath) |
Sets the search paths for icon themes to paths. | |
static QStringList | fallbackSearchPaths () |
static void | setFallbackSearchPaths (const QStringList &paths) |
static QString | themeName () |
Returns the name of the current icon theme. | |
static void | setThemeName (const QString &path) |
Sets the current icon theme to name. | |
static QString | fallbackThemeName () |
static void | setFallbackThemeName (const QString &name) |
Friends | |
Q_GUI_EXPORT QDataStream & | operator<< (QDataStream &s, const QIcon &icon) |
Writes the given icon to the given stream as a PNG image. | |
Q_GUI_EXPORT QDataStream & | operator>> (QDataStream &s, QIcon &icon) |
Reads an image, or a set of images, from the given stream into the given icon. | |
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.
typedef QIconPrivate* QIcon::DataPtr |
enum QIcon::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 |
enum QIcon::State |
|
strong |
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
QIcon::QIcon | ( | const QPixmap & | pixmap | ) |
QIcon::QIcon | ( | const QIcon & | other | ) |
|
inlinenoexcept |
|
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.
|
explicit |
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).
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.
The cacheKey() will change when the icon is altered via addPixmap() or addFile().
Cache keys are mostly useful in conjunction with caching.
|
static |
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.
|
static |
Returns the name of the fallback icon theme.
If not set, the fallback icon theme will be defined by the platform.
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.
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:
|
static |
|
static |
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.
|
static |
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
.
|
static |
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
.
bool QIcon::isMask | ( | ) | const |
Returns true
if this icon has been marked as a mask image. Certain platforms render mask icons differently (for example, menu icons on \macos).
bool QIcon::isNull | ( | ) | const |
QString QIcon::name | ( | ) | const |
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().
QIcon::operator QVariant | ( | ) | const |
|
delete |
|
delete |
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.
|
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).
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.
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.
Returns a pixmap with the requested size, devicePixelRatio, mode, and state, generating one with the given mode and state 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.
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.
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.
|
static |
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:
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().
void QIcon::setIsMask | ( | bool | isMask | ) |
Sets the current icon theme to name.
If the theme matches the name of an installed font that provides named glyphs, then QIcon::fromTheme calls that match one of the glyphs will produce an icon for that glyph.
Otherwise, the theme 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.
|
static |
Sets the search paths for icon themes to paths.
The content of paths should follow the theme format documented by setThemeName().
|
static |
Returns the name of the current icon theme.
If not set, the current icon theme will be defined by the platform.
|
static |
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.
|
friend |
|
friend |
Reads an image, or a set of images, from the given stream into the given icon.
Definition at line 1947 of file qicon.cpp.
References QImageReader::fileName().