Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquicktextmetrics.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 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
5
6#include <QFont>
7#include <QTextOption>
8
10
43 m_metrics(m_font),
44 m_elide(Qt::ElideNone),
45 m_elideWidth(0),
46 m_renderType(QQuickText::QtRendering)
47{
48}
49
56{
57 return m_font;
58}
59
61{
62 if (m_font != font) {
63 m_font = font;
64 m_metrics = QFontMetricsF(m_font);
67 }
68}
69
76{
77 return m_text;
78}
79
81{
82 if (m_text != text) {
83 m_text = text;
86 }
87}
88
103{
104 return m_elide;
105}
106
108{
109 if (m_elide != elide) {
110 m_elide = elide;
113 }
114}
115
125{
126 return m_elideWidth;
127}
128
130{
131 if (m_elideWidth != elideWidth) {
132 m_elideWidth = elideWidth;
135 }
136}
137
148{
150 option.setUseDesignMetrics(m_renderType == QQuickText::QtRendering);
151 return m_metrics.horizontalAdvance(m_text, option);
152}
153
163{
165 option.setUseDesignMetrics(m_renderType == QQuickText::QtRendering);
166 return m_metrics.boundingRect(m_text, option);
167}
168
182{
183 return boundingRect().width();
184}
185
199{
200 return boundingRect().height();
201}
202
212{
214 option.setUseDesignMetrics(m_renderType == QQuickText::QtRendering);
215 return m_metrics.tightBoundingRect(m_text, option);
216}
217
229{
230 return m_metrics.elidedText(m_text, m_elide, m_elideWidth);
231}
232
249{
250 return m_renderType;
251}
252
254{
255 if (m_renderType == renderType)
256 return;
257
258 m_renderType = renderType;
260}
261
263
264#include "moc_qquicktextmetrics_p.cpp"
\reentrant \inmodule QtGui
QRectF boundingRect(const QString &string) const
Returns the bounding rectangle of the characters in the string specified by text.
qreal horizontalAdvance(const QString &string, int length=-1) const
Returns the horizontal advance in pixels of the first length characters of text.
QRectF tightBoundingRect(const QString &text) const
QString elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags=0) const
\reentrant
Definition qfont.h:20
\inmodule QtCore
Definition qobject.h:90
void setElideWidth(qreal elideWidth)
void setRenderType(QQuickText::RenderType renderType)
void setText(const QString &text)
QQuickTextMetrics(QObject *parent=nullptr)
\qmltype TextMetrics \instantiates QQuickTextMetrics \inqmlmodule QtQuick
void renderTypeChanged()
QQuickText::RenderType renderType
void setFont(const QFont &font)
void setElide(Qt::TextElideMode elide)
Qt::TextElideMode elide
void elideWidthChanged()
\inmodule QtCore\reentrant
Definition qrect.h:483
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:718
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:715
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\reentrant
Definition qtextoption.h:18
QString text
Combined button and popup list for selecting options.
TextElideMode
Definition qnamespace.h:187
GLuint GLenum option
#define emit
double qreal
Definition qtypes.h:92
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent