Qt 6.x
The Qt SDK
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{
21public:
22 enum Mode { Normal, Disabled, Active, Selected };
23 enum State { On, Off };
24
25 QIcon() noexcept;
26 QIcon(const QPixmap &pixmap);
27 QIcon(const QIcon &other);
28 QIcon(QIcon &&other) noexcept
29 : d(std::exchange(other.d, nullptr))
30 {}
31 explicit QIcon(const QString &fileName); // file or resource name
32 explicit QIcon(QIconEngine *engine);
33 ~QIcon();
34 QIcon &operator=(const QIcon &other);
35 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QIcon)
36 inline void swap(QIcon &other) noexcept
37 { qt_ptr_swap(d, other.d); }
38 bool operator==(const QIcon &) const = delete;
39 bool operator!=(const QIcon &) const = delete;
40
41 operator QVariant() const;
42
43 QPixmap pixmap(const QSize &size, Mode mode = Normal, State state = Off) const;
44 inline QPixmap pixmap(int w, int h, Mode mode = Normal, State state = Off) const
45 { return pixmap(QSize(w, h), mode, state); }
46 inline QPixmap pixmap(int extent, Mode mode = Normal, State state = Off) const
47 { return pixmap(QSize(extent, extent), mode, state); }
48 QPixmap pixmap(const QSize &size, qreal devicePixelRatio, Mode mode = Normal, State state = Off) const;
49#if QT_DEPRECATED_SINCE(6, 0)
50 QT_DEPRECATED_VERSION_X_6_0("Use pixmap(size, devicePixelRatio) instead")
51 QPixmap pixmap(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
52#endif
53
54 QSize actualSize(const QSize &size, Mode mode = Normal, State state = Off) const;
55#if QT_DEPRECATED_SINCE(6, 0)
56 QT_DEPRECATED_VERSION_X_6_0("Use actualSize(size) instead")
57 QSize actualSize(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
58#endif
59
60 QString name() const;
61
62 void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const;
63 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
64 { paint(painter, QRect(x, y, w, h), alignment, mode, state); }
65
66 bool isNull() const;
67 bool isDetached() const;
68 void detach();
69
70 qint64 cacheKey() const;
71
72 void addPixmap(const QPixmap &pixmap, Mode mode = Normal, State state = Off);
73 void addFile(const QString &fileName, const QSize &size = QSize(), Mode mode = Normal, State state = Off);
74
75 QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const;
76
77 void setIsMask(bool isMask);
78 bool isMask() const;
79
80 static QIcon fromTheme(const QString &name);
81 static QIcon fromTheme(const QString &name, const QIcon &fallback);
82 static bool hasThemeIcon(const QString &name);
83
84 static QStringList themeSearchPaths();
85 static void setThemeSearchPaths(const QStringList &searchpath);
86
87 static QStringList fallbackSearchPaths();
88 static void setFallbackSearchPaths(const QStringList &paths);
89
90 static QString themeName();
91 static void setThemeName(const QString &path);
92
93 static QString fallbackThemeName();
94 static void setFallbackThemeName(const QString &name);
95
96private:
98#if !defined(QT_NO_DATASTREAM)
99 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
100 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
101#endif
102
103public:
105 inline DataPtr &data_ptr() { return d; }
106};
107
108Q_DECLARE_SHARED(QIcon)
109
110#if !defined(QT_NO_DATASTREAM)
111Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
112Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
113#endif
114
115#ifndef QT_NO_DEBUG_STREAM
116Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QIcon &);
117#endif
118
119Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,
120 qreal *sourceDevicePixelRatio = nullptr);
121
123
124#endif // QICON_H
\inmodule QtCore\reentrant
Definition qdatastream.h:30
\inmodule QtCore
The QIconEngine class provides an abstract base class for QIcon renderers.
Definition qiconengine.h:15
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
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 o...
Definition qicon.h:44
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition qicon.h:22
@ Active
Definition qicon.h:22
QIconPrivate * DataPtr
Definition qicon.h:104
bool operator!=(const QIcon &) const =delete
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 o...
Definition qicon.h:46
DataPtr & data_ptr()
Definition qicon.h:105
bool operator==(const QIcon &) const =delete
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 o...
Definition qicon.h:63
Definition qlist.h:74
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qvariant.h:64
\inmodule QtGui
Definition qwindow.h:63
QPainter paint
rect
[4]
uint alignment
else opt state
[0]
Combined button and popup list for selecting options.
@ AlignCenter
Definition qnamespace.h:162
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QIcon &)
Definition qicon.cpp:1393
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QIcon &)
Definition qicon.cpp:1432
Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio, qreal *sourceDevicePixelRatio=nullptr)
Definition qicon.cpp:1528
static QString themeName()
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei const GLuint * paths
GLuint name
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLsizei const GLchar *const * path
constexpr void qt_ptr_swap(T *&lhs, T *&rhs) noexcept
Definition qswap.h:43
#define QT_DEPRECATED_VERSION_X_6_0(text)
long long qint64
Definition qtypes.h:55
double qreal
Definition qtypes.h:92
QDataStream & operator<<(QDataStream &out, const MyClass &myObj)
[4]
QDataStream & operator>>(QDataStream &in, MyClass &myObj)
QSharedPointer< T > other(t)
[5]
widget render & pixmap
QPainter painter(this)
[7]
aWidget window() -> setWindowTitle("New Window Title")
[2]
QJSEngine engine
[0]