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