Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qicon.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QICON_H
5#define QICON_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qsize.h>
9#include <QtCore/qlist.h>
10#include <QtGui/qpixmap.h>
11
13
14
15class QIconPrivate;
16class QIconEngine;
17class QPainter;
18
19class Q_GUI_EXPORT QIcon
20{
21 Q_GADGET
22public:
23 enum Mode { Normal, Disabled, Active, Selected };
24 Q_ENUM(Mode);
25 enum State { On, Off };
26 Q_ENUM(State);
27
28 enum class ThemeIcon {
29 AddressBookNew,
30 ApplicationExit,
31 AppointmentNew,
32 CallStart,
33 CallStop,
34 ContactNew,
35 DocumentNew,
36 DocumentOpen,
37 DocumentOpenRecent,
38 DocumentPageSetup,
39 DocumentPrint,
40 DocumentPrintPreview,
41 DocumentProperties,
42 DocumentRevert,
43 DocumentSave,
44 DocumentSaveAs,
45 DocumentSend,
46 EditClear,
47 EditCopy,
48 EditCut,
49 EditDelete,
50 EditFind,
51 EditPaste,
52 EditRedo,
53 EditSelectAll,
54 EditUndo,
55 FolderNew,
56 FormatIndentLess,
57 FormatIndentMore,
58 FormatJustifyCenter,
59 FormatJustifyFill,
60 FormatJustifyLeft,
61 FormatJustifyRight,
62 FormatTextDirectionLtr,
63 FormatTextDirectionRtl,
64 FormatTextBold,
65 FormatTextItalic,
66 FormatTextUnderline,
67 FormatTextStrikethrough,
68 GoDown,
69 GoHome,
70 GoNext,
71 GoPrevious,
72 GoUp,
73 HelpAbout,
74 HelpFaq,
75 InsertImage,
76 InsertLink,
77 InsertText,
78 ListAdd,
79 ListRemove,
80 MailForward,
81 MailMarkImportant,
82 MailMarkRead,
83 MailMarkUnread,
84 MailMessageNew,
85 MailReplyAll,
86 MailReplySender,
87 MailSend,
88 MediaEject,
89 MediaPlaybackPause,
90 MediaPlaybackStart,
91 MediaPlaybackStop,
92 MediaRecord,
93 MediaSeekBackward,
94 MediaSeekForward,
95 MediaSkipBackward,
96 MediaSkipForward,
97 ObjectRotateLeft,
98 ObjectRotateRight,
99 ProcessStop,
100 SystemLockScreen,
101 SystemLogOut,
102 SystemSearch,
103 SystemReboot,
104 SystemShutdown,
105 ToolsCheckSpelling,
106 ViewFullscreen,
107 ViewRefresh,
108 ViewRestore,
109 WindowClose,
110 WindowNew,
111 ZoomFitBest,
112 ZoomIn,
113 ZoomOut,
114
115 AudioCard,
116 AudioInputMicrophone,
117 Battery,
118 CameraPhoto,
119 CameraVideo,
120 CameraWeb,
121 Computer,
122 DriveHarddisk,
123 DriveOptical,
124 InputGaming,
125 InputKeyboard,
126 InputMouse,
127 InputTablet,
128 MediaFlash,
129 MediaOptical,
130 MediaTape,
131 MultimediaPlayer,
132 NetworkWired,
133 NetworkWireless,
134 Phone,
135 Printer,
136 Scanner,
137 VideoDisplay,
138
139 AppointmentMissed,
140 AppointmentSoon,
141 AudioVolumeHigh,
142 AudioVolumeLow,
143 AudioVolumeMedium,
144 AudioVolumeMuted,
145 BatteryCaution,
146 BatteryLow,
147 DialogError,
148 DialogInformation,
149 DialogPassword,
150 DialogQuestion,
151 DialogWarning,
152 FolderDragAccept,
153 FolderOpen,
154 FolderVisiting,
155 ImageLoading,
156 ImageMissing,
157 MailAttachment,
158 MailUnread,
159 MailRead,
160 MailReplied,
161 MediaPlaylistRepeat,
162 MediaPlaylistShuffle,
163 NetworkOffline,
164 PrinterPrinting,
165 SecurityHigh,
166 SecurityLow,
167 SoftwareUpdateAvailable,
168 SoftwareUpdateUrgent,
169 SyncError,
170 SyncSynchronizing,
171 UserAvailable,
172 UserOffline,
173 WeatherClear,
174 WeatherClearNight,
175 WeatherFewClouds,
176 WeatherFewCloudsNight,
177 WeatherFog,
178 WeatherShowers,
179 WeatherSnow,
180 WeatherStorm,
181
182 NThemeIcons
183 };
184 Q_ENUM(ThemeIcon);
185
186 QIcon() noexcept;
187 QIcon(const QPixmap &pixmap);
188 QIcon(const QIcon &other);
189 QIcon(QIcon &&other) noexcept
190 : d(std::exchange(other.d, nullptr))
191 {}
192 explicit QIcon(const QString &fileName); // file or resource name
193 explicit QIcon(QIconEngine *engine);
194 ~QIcon();
195 QIcon &operator=(const QIcon &other);
196 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QIcon)
197 inline void swap(QIcon &other) noexcept
198 { qt_ptr_swap(d, other.d); }
199 bool operator==(const QIcon &) const = delete;
200 bool operator!=(const QIcon &) const = delete;
201
202 operator QVariant() const;
203
204 QPixmap pixmap(const QSize &size, Mode mode = Normal, State state = Off) const;
205 inline QPixmap pixmap(int w, int h, Mode mode = Normal, State state = Off) const
206 { return pixmap(QSize(w, h), mode, state); }
207 inline QPixmap pixmap(int extent, Mode mode = Normal, State state = Off) const
208 { return pixmap(QSize(extent, extent), mode, state); }
209 QPixmap pixmap(const QSize &size, qreal devicePixelRatio, Mode mode = Normal, State state = Off) const;
210#if QT_DEPRECATED_SINCE(6, 0)
211 QT_DEPRECATED_VERSION_X_6_0("Use pixmap(size, devicePixelRatio) instead")
212 QPixmap pixmap(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
213#endif
214
215 QSize actualSize(const QSize &size, Mode mode = Normal, State state = Off) const;
216#if QT_DEPRECATED_SINCE(6, 0)
217 QT_DEPRECATED_VERSION_X_6_0("Use actualSize(size) instead")
218 QSize actualSize(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
219#endif
220
221 QString name() const;
222
223 void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const;
224 inline void paint(QPainter *painter, int x, int y, int w, int h, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const
225 { paint(painter, QRect(x, y, w, h), alignment, mode, state); }
226
227 bool isNull() const;
228 bool isDetached() const;
229 void detach();
230
231 qint64 cacheKey() const;
232
233 void addPixmap(const QPixmap &pixmap, Mode mode = Normal, State state = Off);
234 void addFile(const QString &fileName, const QSize &size = QSize(), Mode mode = Normal, State state = Off);
235
236 QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const;
237
238 void setIsMask(bool isMask);
239 bool isMask() const;
240
241 static QIcon fromTheme(const QString &name);
242 static QIcon fromTheme(const QString &name, const QIcon &fallback);
243 static bool hasThemeIcon(const QString &name);
244
245 static QIcon fromTheme(ThemeIcon icon);
246 static QIcon fromTheme(ThemeIcon icon, const QIcon &fallback);
247 static bool hasThemeIcon(ThemeIcon icon);
248
249 static QStringList themeSearchPaths();
250 static void setThemeSearchPaths(const QStringList &searchpath);
251
252 static QStringList fallbackSearchPaths();
253 static void setFallbackSearchPaths(const QStringList &paths);
254
255 static QString themeName();
256 static void setThemeName(const QString &path);
257
258 static QString fallbackThemeName();
259 static void setFallbackThemeName(const QString &name);
260
261private:
262 QIconPrivate *d;
263#if !defined(QT_NO_DATASTREAM)
264 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
265 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
266#endif
267
268public:
269 typedef QIconPrivate * DataPtr;
270 inline DataPtr &data_ptr() { return d; }
271};
272
274
275#if !defined(QT_NO_DATASTREAM)
276Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
277Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
278#endif
279
280#ifndef QT_NO_DEBUG_STREAM
281Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QIcon &);
282#endif
283
284Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,
285 qreal *sourceDevicePixelRatio = nullptr);
286
287QT_END_NAMESPACE
288
289#endif // QICON_H
\inmodule QtCore\reentrant
Definition qdatastream.h:50
\macro qGuiApp
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
friend class QPainter
static QPlatformTheme::IconOptions toThemeIconOptions(QAbstractFileIconProvider::Options options)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2568
Q_GLOBAL_STATIC(QReadWriteLock, g_updateMutex)