Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qfont.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 QFONT_H
5#define QFONT_H
6
7#include <QtCore/qshareddata.h>
8#include <QtGui/qtguiglobal.h>
9#include <QtGui/qwindowdefs.h>
10#include <QtCore/qstring.h>
11
12
14
15
16class QFontPrivate; /* don't touch */
17class QVariant;
18
19class Q_GUI_EXPORT QFont
20{
22public:
23 enum StyleHint {
24 Helvetica, SansSerif = Helvetica,
25 Times, Serif = Times,
26 Courier, TypeWriter = Courier,
27 OldEnglish, Decorative = OldEnglish,
32 Fantasy
33 };
34 Q_ENUM(StyleHint)
35
37 PreferDefault = 0x0001,
38 PreferBitmap = 0x0002,
39 PreferDevice = 0x0004,
40 PreferOutline = 0x0008,
41 ForceOutline = 0x0010,
42 PreferMatch = 0x0020,
43 PreferQuality = 0x0040,
44 PreferAntialias = 0x0080,
45 NoAntialias = 0x0100,
46 NoSubpixelAntialias = 0x0800,
47 PreferNoShaping = 0x1000,
48 NoFontMerging = 0x8000
49 };
50 Q_ENUM(StyleStrategy)
51
53 PreferDefaultHinting = 0,
54 PreferNoHinting = 1,
55 PreferVerticalHinting = 2,
56 PreferFullHinting = 3
57 };
58 Q_ENUM(HintingPreference)
59
60 enum Weight {
61 Thin = 100,
62 ExtraLight = 200,
63 Light = 300,
64 Normal = 400,
65 Medium = 500,
66 DemiBold = 600,
67 Bold = 700,
68 ExtraBold = 800,
69 Black = 900
70 };
71 Q_ENUM(Weight)
72
73 enum Style {
76 StyleOblique
77 };
78 Q_ENUM(Style)
79
80 enum Stretch {
81 AnyStretch = 0,
82 UltraCondensed = 50,
83 ExtraCondensed = 62,
84 Condensed = 75,
85 SemiCondensed = 87,
86 Unstretched = 100,
87 SemiExpanded = 112,
88 Expanded = 125,
89 ExtraExpanded = 150,
90 UltraExpanded = 200
91 };
92 Q_ENUM(Stretch)
93
99 Capitalize
100 };
101 Q_ENUM(Capitalization)
102
105 AbsoluteSpacing
106 };
107 Q_ENUM(SpacingType)
108
110 NoPropertiesResolved = 0x0000,
111 FamilyResolved = 0x0001,
112 SizeResolved = 0x0002,
113 StyleHintResolved = 0x0004,
114 StyleStrategyResolved = 0x0008,
115 WeightResolved = 0x0010,
116 StyleResolved = 0x0020,
117 UnderlineResolved = 0x0040,
118 OverlineResolved = 0x0080,
119 StrikeOutResolved = 0x0100,
120 FixedPitchResolved = 0x0200,
121 StretchResolved = 0x0400,
122 KerningResolved = 0x0800,
123 CapitalizationResolved = 0x1000,
124 LetterSpacingResolved = 0x2000,
125 WordSpacingResolved = 0x4000,
126 HintingPreferenceResolved = 0x8000,
127 StyleNameResolved = 0x10000,
128 FamiliesResolved = 0x20000,
129 FeaturesResolved = 0x40000,
130 AllPropertiesResolved = 0x7ffff
131 };
132 Q_ENUM(ResolveProperties)
133
134 QFont();
135
136 QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
137 explicit QFont(const QStringList &families, int pointSize = -1, int weight = -1, bool italic = false);
138 QFont(const QFont &font, const QPaintDevice *pd);
139 QFont(const QFont &font);
140 ~QFont();
141
142 void swap(QFont &other) noexcept
143 { d.swap(other.d); std::swap(resolve_mask, other.resolve_mask); }
144
145 QString family() const;
146 void setFamily(const QString &);
147
148 QStringList families() const;
149 void setFamilies(const QStringList &);
150
151 QString styleName() const;
152 void setStyleName(const QString &);
153
154 int pointSize() const;
155 void setPointSize(int);
156 qreal pointSizeF() const;
157 void setPointSizeF(qreal);
158
159 int pixelSize() const;
160 void setPixelSize(int);
161
162 Weight weight() const;
163 void setWeight(Weight weight);
164
165 inline bool bold() const;
166 inline void setBold(bool);
167
168 void setStyle(Style style);
169 Style style() const;
170
171 inline bool italic() const;
172 inline void setItalic(bool b);
173
174 bool underline() const;
175 void setUnderline(bool);
176
177 bool overline() const;
178 void setOverline(bool);
179
180 bool strikeOut() const;
181 void setStrikeOut(bool);
182
183 bool fixedPitch() const;
184 void setFixedPitch(bool);
185
186 bool kerning() const;
187 void setKerning(bool);
188
189 StyleHint styleHint() const;
190 StyleStrategy styleStrategy() const;
191 void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
192 void setStyleStrategy(StyleStrategy s);
193
194 int stretch() const;
195 void setStretch(int);
196
197 qreal letterSpacing() const;
198 SpacingType letterSpacingType() const;
199 void setLetterSpacing(SpacingType type, qreal spacing);
200
201 qreal wordSpacing() const;
202 void setWordSpacing(qreal spacing);
203
204 void setCapitalization(Capitalization);
205 Capitalization capitalization() const;
206
207 void setHintingPreference(HintingPreference hintingPreference);
208 HintingPreference hintingPreference() const;
209
210 void setFeature(const char *feature, quint32 value);
211 void setFeature(quint32 tag, quint32 value);
212 void unsetFeature(quint32 tag);
213 void unsetFeature(const char *feature);
214 quint32 featureValue(quint32 tag) const;
215 bool isFeatureSet(quint32 tag) const;
216 QList<quint32> featureTags() const;
217 void clearFeatures();
218
219 static QByteArray tagToString(quint32 tag);
220 static quint32 stringToTag(const char *tagString);
221
222 // dupicated from QFontInfo
223 bool exactMatch() const;
224
225 QFont &operator=(const QFont &);
226 bool operator==(const QFont &) const;
227 bool operator!=(const QFont &) const;
228 bool operator<(const QFont &) const;
229 operator QVariant() const;
230 bool isCopyOf(const QFont &) const;
231 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFont)
232
233 QString key() const;
234
235 QString toString() const;
236 bool fromString(const QString &);
237
238 static QString substitute(const QString &);
239 static QStringList substitutes(const QString &);
240 static QStringList substitutions();
241 static void insertSubstitution(const QString&, const QString &);
242 static void insertSubstitutions(const QString&, const QStringList &);
243 static void removeSubstitutions(const QString &);
244 static void initialize();
245 static void cleanup();
246 static void cacheStatistics();
247
248 QString defaultFamily() const;
249
250 QFont resolve(const QFont &) const;
251 inline uint resolveMask() const { return resolve_mask; }
252 inline void setResolveMask(uint mask) { resolve_mask = mask; }
253
254#if QT_DEPRECATED_SINCE(6, 0)
255 QT_DEPRECATED_VERSION_X_6_0("Use setWeight() instead") void setLegacyWeight(int legacyWeight);
256 QT_DEPRECATED_VERSION_X_6_0("Use weight() instead") int legacyWeight() const;
257#endif
258
259private:
260 explicit QFont(QFontPrivate *);
261
262 void detach();
263
264
265 friend class QFontPrivate;
266 friend class QFontDialogPrivate;
267 friend class QFontMetrics;
268 friend class QFontMetricsF;
269 friend class QFontInfo;
270 friend class QPainter;
271 friend class QPainterPrivate;
272 friend class QApplication;
273 friend class QWidget;
274 friend class QWidgetPrivate;
275 friend class QTextLayout;
276 friend class QTextEngine;
277 friend class QStackTextEngine;
278 friend class QTextLine;
279 friend struct QScriptLine;
280 friend class QOpenGLContext;
281 friend class QWin32PaintEngine;
282 friend class QAlphaPaintEngine;
283 friend class QPainterPath;
284 friend class QTextItemInt;
286 friend class QPainterReplayer;
287 friend class QPaintBufferEngine;
289 friend class QFontEngine;
290
291#ifndef QT_NO_DATASTREAM
292 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
293 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
294#endif
295
296#ifndef QT_NO_DEBUG_STREAM
297 friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
298#endif
299
301 uint resolve_mask;
302};
303
304Q_DECLARE_SHARED(QFont)
305
306Q_GUI_EXPORT size_t qHash(const QFont &font, size_t seed = 0) noexcept;
307
308inline bool QFont::bold() const
309{ return weight() > Medium; }
310
311
312inline void QFont::setBold(bool enable)
313{ setWeight(enable ? Bold : Normal); }
314
315inline bool QFont::italic() const
316{
317 return (style() != StyleNormal);
318}
319
320inline void QFont::setItalic(bool b) {
322}
323
324
325/*****************************************************************************
326 QFont stream functions
327 *****************************************************************************/
328
329#ifndef QT_NO_DATASTREAM
330Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
332#endif
333
334#ifndef QT_NO_DEBUG_STREAM
335Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
336#endif
337
339
340#endif // QFONT_H
The QApplication class manages the GUI application's control flow and main settings.
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qdatastream.h:30
\inmodule QtCore
\reentrant
Definition qfontinfo.h:14
\reentrant \inmodule QtGui
\reentrant \inmodule QtGui
\reentrant
Definition qfont.h:20
StyleHint
Style hints are used by the \l{QFont}{font matching} algorithm to find an appropriate default family ...
Definition qfont.h:23
@ Helvetica
Definition qfont.h:24
@ AnyStyle
Definition qfont.h:29
@ Monospace
Definition qfont.h:31
@ System
Definition qfont.h:28
@ Courier
Definition qfont.h:26
@ Cursive
Definition qfont.h:30
void setStyle(Style style)
Sets the style of the font to style.
Definition qfont.cpp:1101
bool italic() const
Returns true if the style() of the font is not QFont::StyleNormal.
Definition qfont.h:315
void swap(QFont &other) noexcept
Definition qfont.h:142
Capitalization
Definition qfont.h:94
@ AllLowercase
Definition qfont.h:97
@ AllUppercase
Definition qfont.h:96
@ MixedCase
Definition qfont.h:95
@ SmallCaps
Definition qfont.h:98
SpacingType
Definition qfont.h:103
@ PercentageSpacing
Definition qfont.h:104
ResolveProperties
Definition qfont.h:109
void setBold(bool)
If enable is true sets the font's weight to \l{Weight}{QFont::Bold}; otherwise sets the weight to \l{...
Definition qfont.h:312
void setItalic(bool b)
Sets the style() of the font to QFont::StyleItalic if enable is true; otherwise the style is set to Q...
Definition qfont.h:320
HintingPreference
Definition qfont.h:52
void setResolveMask(uint mask)
Definition qfont.h:252
uint resolveMask() const
Definition qfont.h:251
Stretch
Predefined stretch values that follow the CSS naming convention.
Definition qfont.h:80
Style style() const
Returns the style of the font.
Definition qfont.cpp:1090
StyleStrategy
The style strategy tells the \l{QFont}{font matching} algorithm what type of fonts should be used to ...
Definition qfont.h:36
Weight
Qt uses a weighting scale from 1 to 1000 compatible with OpenType.
Definition qfont.h:60
@ Bold
Definition qfont.h:67
@ Normal
Definition qfont.h:64
void setWeight(Weight weight)
Sets the weight of the font to weight, using the scale defined by \l QFont::Weight enumeration.
Definition qfont.cpp:1190
Style
This enum describes the different styles of glyphs that are used to display text.
Definition qfont.h:73
@ StyleItalic
Definition qfont.h:75
@ StyleNormal
Definition qfont.h:74
Definition qlist.h:74
\inmodule QtGui
\inmodule QtGui
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
Internal QTextItem.
\reentrant
Definition qtextlayout.h:70
\reentrant
\inmodule QtCore
Definition qvariant.h:64
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
qreal spacing
Combined button and popup list for selecting options.
constexpr bool operator!=(const timespec &t1, const timespec &t2)
AudioChannelLayoutTag tag
static bool initialize()
Definition qctf.cpp:67
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QFont &)
Q_GUI_EXPORT size_t qHash(const QFont &font, size_t seed=0) noexcept
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QFont &)
static QFixed kerning(int left, int right, const QFontEngine::KernPair *pairs, int numPairs)
GLboolean GLboolean GLboolean b
GLuint64 key
GLuint GLuint GLfloat weight
GLenum type
GLboolean enable
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
const GLchar * tagString
GLdouble s
[6]
Definition qopenglext.h:235
static bool fromString(const QMetaObject *mo, QString s, Allocate &&allocate)
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1219
static bool operator<(const QSettingsIniKey &k1, const QSettingsIniKey &k2)
@ Medium
#define QT_DEPRECATED_VERSION_X_6_0(text)
#define Q_ENUM(x)
#define Q_GADGET
unsigned int quint32
Definition qtypes.h:45
unsigned int uint
Definition qtypes.h:29
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 setStyle(proxy)
char * toString(const MyType &t)
[31]