Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QTextLayout Class Reference

\reentrant More...

#include <qtextlayout.h>

+ Collaboration diagram for QTextLayout:

Classes

class  FormatRange
 \reentrant More...
 

Public Types

enum  GlyphRunRetrievalFlag : quint16 {
  RetrieveGlyphIndexes = 0x1 , RetrieveGlyphPositions = 0x2 , RetrieveStringIndexes = 0x4 , RetrieveString = 0x8 ,
  DefaultRetrievalFlags = RetrieveGlyphIndexes | RetrieveGlyphPositions , RetrieveAll = 0xffff
}
 
enum  CursorMode { SkipCharacters , SkipWords }
 \value SkipCharacters \value SkipWords More...
 

Public Member Functions

 QTextLayout ()
 Constructs an empty text layout.
 
 QTextLayout (const QString &text)
 Constructs a text layout to lay out the given text.
 
 QTextLayout (const QString &text, const QFont &font, const QPaintDevice *paintdevice=nullptr)
 
 QTextLayout (const QTextBlock &b)
 
 ~QTextLayout ()
 Destructs the layout.
 
void setFont (const QFont &f)
 Sets the layout's font to the given font.
 
QFont font () const
 Returns the current font that is used for the layout, or a default font if none is set.
 
void setRawFont (const QRawFont &rawFont)
 
void setText (const QString &string)
 Sets the layout's text to the given string.
 
QString text () const
 Returns the layout's text.
 
void setTextOption (const QTextOption &option)
 Sets the text option structure that controls the layout process to the given option.
 
const QTextOptiontextOption () const
 Returns the current text option used to control the layout process.
 
void setPreeditArea (int position, const QString &text)
 Sets the position and text of the area in the layout that is processed before editing occurs.
 
int preeditAreaPosition () const
 Returns the position of the area in the text layout that will be processed before editing occurs.
 
QString preeditAreaText () const
 Returns the text that is inserted in the layout before editing occurs.
 
void setFormats (const QList< FormatRange > &overrides)
 
QList< FormatRangeformats () const
 
void clearFormats ()
 
void setCacheEnabled (bool enable)
 Enables caching of the complete layout information if enable is true; otherwise disables layout caching.
 
bool cacheEnabled () const
 Returns true if the complete layout information is cached; otherwise returns false.
 
void setCursorMoveStyle (Qt::CursorMoveStyle style)
 Sets the visual cursor movement style to the given style.
 
Qt::CursorMoveStyle cursorMoveStyle () const
 The cursor movement style of this QTextLayout.
 
void beginLayout ()
 Begins the layout process.
 
void endLayout ()
 Ends the layout process.
 
void clearLayout ()
 
QTextLine createLine ()
 Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise returns an invalid text line.
 
int lineCount () const
 Returns the number of lines in this text layout.
 
QTextLine lineAt (int i) const
 Returns the {i}-th line of text in this text layout.
 
QTextLine lineForTextPosition (int pos) const
 Returns the line that contains the cursor position specified by pos.
 
bool isValidCursorPosition (int pos) const
 Returns true if position pos is a valid cursor position.
 
int nextCursorPosition (int oldPos, CursorMode mode=SkipCharacters) const
 Returns the next valid cursor position after oldPos that respects the given cursor mode.
 
int previousCursorPosition (int oldPos, CursorMode mode=SkipCharacters) const
 Returns the first valid cursor position before oldPos that respects the given cursor mode.
 
int leftCursorPosition (int oldPos) const
 Returns the cursor position to the left of oldPos, next to it.
 
int rightCursorPosition (int oldPos) const
 Returns the cursor position to the right of oldPos, next to it.
 
void draw (QPainter *p, const QPointF &pos, const QList< FormatRange > &selections=QList< FormatRange >(), const QRectF &clip=QRectF()) const
 Draws the whole layout on the painter p at the position specified by pos.
 
void drawCursor (QPainter *p, const QPointF &pos, int cursorPosition) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws a text cursor with the current pen at the given position using the painter specified.
 
void drawCursor (QPainter *p, const QPointF &pos, int cursorPosition, int width) const
 Draws a text cursor with the current pen and the specified width at the given position using the painter specified.
 
QPointF position () const
 
void setPosition (const QPointF &p)
 Moves the text layout to point p.
 
QRectF boundingRect () const
 The smallest rectangle that contains all the lines in the layout.
 
qreal minimumWidth () const
 The minimum width the layout needs.
 
qreal maximumWidth () const
 The maximum width the layout could expand to; this is essentially the width of the entire text.
 
QList< QGlyphRunglyphRuns (int from=-1, int length=-1, GlyphRunRetrievalFlags flags=DefaultRetrievalFlags) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the glyph indexes and positions for all glyphs corresponding to the length characters starting at the position from in this QTextLayout.
 
QTextEngineengine () const
 
void setFlags (int flags)
 

Friends

class QPainter
 
class QGraphicsSimpleTextItemPrivate
 
class QGraphicsSimpleTextItem
 
void qt_format_text (const QFont &font, const QRectF &_r, int tf, const QTextOption *, const QString &str, QRectF *brect, int tabstops, int *tabarray, int tabarraylen, QPainter *painter)
 

Detailed Description

\reentrant

The QTextLayout class is used to lay out and render text. \inmodule QtGui

It offers many features expected from a modern text layout engine, including Unicode compliant rendering, line breaking and handling of cursor positioning. It can also produce and render device independent layout, something that is important for WYSIWYG applications.

The class has a rather low level API and unless you intend to implement your own text rendering for some specialized widget, you probably won't need to use it directly.

QTextLayout can be used with both plain and rich text.

QTextLayout can be used to create a sequence of QTextLine instances with given widths and can position them independently on the screen. Once the layout is done, these lines can be drawn on a paint device.

The text to be laid out can be provided in the constructor or set with setText().

The layout can be seen as a sequence of QTextLine objects; use createLine() to create a QTextLine instance, and lineAt() or lineForTextPosition() to retrieve created lines.

Here is a code snippet that demonstrates the layout phase:

int leading = fontMetrics.leading();
while (true) {
if (!line.isValid())
break;
line.setLineWidth(lineWidth);
height += leading;
line.setPosition(QPointF(0, height));
height += line.height();
}

The text can then be rendered by calling the layout's draw() function:

It is also possible to draw each line individually, for instance to draw the last line that fits into a widget elided:

int lineSpacing = fontMetrics.lineSpacing();
int y = 0;
while (true) {
if (!line.isValid())
break;
line.setLineWidth(width());
const int nextLineY = y + lineSpacing;
if (height() >= nextLineY + lineSpacing) {
line.draw(&painter, QPoint(0, y));
y = nextLineY;
} else {
const QString lastLine = content.mid(line.textStart());
const QString elidedLastLine = fontMetrics.elidedText(lastLine, Qt::ElideRight, width());
painter.drawText(QPoint(0, y + fontMetrics.ascent()), elidedLastLine);
break;
}
}

For a given position in the text you can find a valid cursor position with isValidCursorPosition(), nextCursorPosition(), and previousCursorPosition().

The QTextLayout itself can be positioned with setPosition(); it has a boundingRect(), and a minimumWidth() and a maximumWidth().

See also
QStaticText

Definition at line 69 of file qtextlayout.h.

Member Enumeration Documentation

◆ CursorMode

\value SkipCharacters \value SkipWords

Enumerator
SkipCharacters 
SkipWords 

Definition at line 137 of file qtextlayout.h.

◆ GlyphRunRetrievalFlag

Since
6.5

GlyphRunRetrievalFlag specifies flags passed to the glyphRuns() functions to determine which properties of the layout are returned in the QGlyphRun objects. Since each property will consume memory and may require additional allocations, it is a good practice to only request the properties you will need to access later.

\value RetrieveGlyphIndexes Retrieves the indexes in the font which correspond to the glyphs. \value RetrieveGlyphPositions Retrieves the relative positions of the glyphs in the layout. \value RetrieveStringIndexes Retrieves the indexes in the original string that correspond to each of the glyphs. \value RetrieveString Retrieves the original source string from the layout. \value RetrieveAll Retrieves all available properties of the layout. \omitvalue DefaultRetrievalFlags

See also
glyphRuns(), QTextLine::glyphRuns()
Enumerator
RetrieveGlyphIndexes 
RetrieveGlyphPositions 
RetrieveStringIndexes 
RetrieveString 
DefaultRetrievalFlags 
RetrieveAll 

Definition at line 72 of file qtextlayout.h.

Constructor & Destructor Documentation

◆ QTextLayout() [1/4]

QTextLayout::QTextLayout ( )

Constructs an empty text layout.

See also
setText()

Definition at line 320 of file qtextlayout.cpp.

◆ QTextLayout() [2/4]

QTextLayout::QTextLayout ( const QString & text)

Constructs a text layout to lay out the given text.

Definition at line 326 of file qtextlayout.cpp.

References QTextEngine::text, and text().

+ Here is the call graph for this function:

◆ QTextLayout() [3/4]

QTextLayout::QTextLayout ( const QString & text,
const QFont & font,
const QPaintDevice * paintdevice = nullptr )
Since
5.13

Constructs a text layout to lay out the given text with the specified font.

All the metric and layout calculations will be done in terms of the paint device, paintdevice. If paintdevice is \nullptr the calculations will be done in screen metrics.

Definition at line 343 of file qtextlayout.cpp.

References font(), QString::fromLatin1(), QString::isNull(), and text().

+ Here is the call graph for this function:

◆ QTextLayout() [4/4]

QTextLayout::QTextLayout ( const QTextBlock & block)

Constructs a text layout to lay out the given block.

Definition at line 353 of file qtextlayout.cpp.

References QTextEngine::block.

◆ ~QTextLayout()

QTextLayout::~QTextLayout ( )

Destructs the layout.

Definition at line 362 of file qtextlayout.cpp.

References QTextEngine::stackEngine.

Member Function Documentation

◆ beginLayout()

void QTextLayout::beginLayout ( )

Begins the layout process.

Warning
This will invalidate the layout, so all existing QTextLine objects that refer to the previous contents should now be discarded.
See also
endLayout()

Definition at line 593 of file qtextlayout.cpp.

References QTextEngine::clearLineData(), QTextEngine::InLayout, QTextEngine::invalidate(), QTextEngine::itemize(), QTextEngine::layoutData, QTextEngine::LayoutData::layoutState, and qWarning.

Referenced by QItemDelegatePrivate::doTextLayout(), src_gui_text_qtextlayout::Wrapper::elided(), QTextDocumentLayoutPrivate::layoutBlock(), plaintextlayout::Window::paintEvent(), QStaticTextPrivate::paintText(), QQuickTextPrivate::setupTextLayout(), QVideoTextureHelper::SubtitleLayout::update(), QQuickTextInputPrivate::updateLayout(), viewItemTextLayout(), QQC2::viewItemTextLayout(), and src_gui_text_qtextlayout::wrapper0().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ boundingRect()

QRectF QTextLayout::boundingRect ( ) const

The smallest rectangle that contains all the lines in the layout.

Definition at line 876 of file qtextlayout.cpp.

References QList< T >::at(), QFixed::ceil(), QScriptLine::height(), i, QList< T >::isEmpty(), QTextEngine::lines, QFIXED_MAX, qMax(), qMin(), QList< T >::size(), QScriptLine::textWidth, QFixed::toReal(), QScriptLine::width, QScriptLine::x, and QScriptLine::y.

Referenced by QPlainTextDocumentLayout::blockBoundingRect(), QCommonStylePrivate::calculateElidedText(), QQC2::QCommonStylePrivate::calculateElidedText(), draw(), QTextDocumentLayoutPrivate::drawBlock(), glyphRuns(), QTextDocumentLayoutPrivate::hitTest(), QTextDocumentLayoutPrivate::layoutBlock(), QStaticTextPrivate::paintText(), and QQuickTextEdit::updatePaintNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cacheEnabled()

bool QTextLayout::cacheEnabled ( ) const

Returns true if the complete layout information is cached; otherwise returns false.

See also
setCacheEnabled()

Definition at line 556 of file qtextlayout.cpp.

References QTextEngine::cacheGlyphs.

◆ clearFormats()

void QTextLayout::clearFormats ( )
Since
5.6

Clears the list of additional formats supported by the text layout.

See also
formats(), setFormats()

Definition at line 530 of file qtextlayout.cpp.

References setFormats().

Referenced by QQuickTextPrivate::clearFormats(), and QWidgetLineControl::commitPreedit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearLayout()

void QTextLayout::clearLayout ( )
Since
4.4

Clears the line information in the layout. After having called this function, lineCount() returns 0.

Warning
This will invalidate the layout, so all existing QTextLine objects that refer to the previous contents should now be discarded.

Definition at line 638 of file qtextlayout.cpp.

References QTextEngine::clearLineData().

Referenced by QTextBlock::clearLayout(), QPlainTextDocumentLayoutPrivate::relayout(), and QQuickTextPrivate::setupTextLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createLine()

QTextLine QTextLayout::createLine ( )

Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise returns an invalid text line.

The text layout creates a new line object that starts after the last line in the layout, or at the beginning if the layout is empty. The layout maintains an internal cursor, and each line is filled with text from the cursor position onwards when the QTextLine::setLineWidth() function is called.

Once QTextLine::setLineWidth() is called, a new line can be created and filled with text. Repeating this process will lay out the whole block of text contained in the QTextLayout. If there is no text left to be inserted into the layout, the QTextLine returned will not be valid (isValid() will return false).

Definition at line 783 of file qtextlayout.cpp.

References QList< T >::append(), QString::at(), QList< T >::at(), QString::from, QScriptLine::from, QTextEngine::layoutData, QTextEngine::LayoutEmpty, QTextEngine::LayoutFailed, QTextEngine::LayoutData::layoutState, QString::length(), QScriptLine::length, line, QTextEngine::lines, QTextEngine::maxWidth, QFIXED_MAX, qWarning, QTextLine::setNumColumns(), QString::size(), QList< T >::size(), QTextEngine::LayoutData::string, and QScriptLine::trailingSpaces.

Referenced by QItemDelegatePrivate::doTextLayout(), src_gui_text_qtextlayout::Wrapper::elided(), QTextDocumentLayoutPrivate::layoutBlock(), plaintextlayout::Window::paintEvent(), QStaticTextPrivate::paintText(), QQuickTextPrivate::setupTextLayout(), QVideoTextureHelper::SubtitleLayout::update(), QQuickTextInputPrivate::updateLayout(), viewItemTextLayout(), QQC2::viewItemTextLayout(), and src_gui_text_qtextlayout::wrapper0().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cursorMoveStyle()

Qt::CursorMoveStyle QTextLayout::cursorMoveStyle ( ) const

The cursor movement style of this QTextLayout.

The default is Qt::LogicalMoveStyle.

See also
setCursorMoveStyle()

Definition at line 580 of file qtextlayout.cpp.

References Qt::LogicalMoveStyle, QTextEngine::visualMovement, and Qt::VisualMoveStyle.

Referenced by QQuickTextInputPrivate::cursorMoveStyle().

+ Here is the caller graph for this function:

◆ draw()

void QTextLayout::draw ( QPainter * p,
const QPointF & pos,
const QList< FormatRange > & selections = QList<FormatRange>(),
const QRectF & clip = QRectF() ) const

Draws the whole layout on the painter p at the position specified by pos.

The rendered layout includes the given selections and is clipped within the rectangle specified by clip.

Definition at line 1087 of file qtextlayout.cpp.

References QPainterPath::addRect(), addSelectedRegionsToPath(), QList< T >::at(), QTextFormat::BackgroundBrush, boundingRect(), QTextEngine::cacheGlyphs, clipIfValid(), QTextLine::draw(), QTextOption::flags(), QTextEngine::freeMemory(), QFixed::fromReal(), QTextFormat::FullWidthSelection, QRectF::height(), i, Qt::IntersectClip, QRectF::intersected(), QList< T >::isEmpty(), QRectF::isNull(), QTextEngine::isRightToLeft(), QRectF::isValid(), QTextEngine::itemize(), QTextEngine::layoutData, QTextEngine::leadingSpaceWidth(), QList< T >::length(), line, QTextEngine::lines, QTextLine::naturalTextRect(), Qt::NoBrush, ObjectSelectionBrush, QTextEngine::option, QTextFormat::OutlinePen, pos, QTextEngine::position, position(), qCeil(), QFIXED_MAX, QTextLine::rect(), selection, QPainterPath::setFillRule(), QRectF::setRight(), QTextOption::ShowLineAndParagraphSeparators, QList< T >::size(), SuppressBackground, SuppressText, QFixed::toReal(), QRectF::translated(), Qt::WindingFill, QPointF::y(), and QRectF::y().

Referenced by QWidgetLineControl::draw(), QVideoTextureHelper::SubtitleLayout::draw(), QTextDocumentLayoutPrivate::drawBlock(), plaintextlayout::Window::paintEvent(), QStaticTextPrivate::paintText(), QVideoTextureHelper::SubtitleLayout::toImage(), and src_gui_text_qtextlayout::Wrapper::wrapper1().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ drawCursor() [1/2]

void QTextLayout::drawCursor ( QPainter * painter,
const QPointF & position,
int cursorPosition ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws a text cursor with the current pen at the given position using the painter specified.

The corresponding position within the text is specified by cursorPosition.

Definition at line 1271 of file qtextlayout.cpp.

References drawCursor(), and pos.

Referenced by QWidgetLineControl::draw(), QTextDocumentLayoutPrivate::drawBlock(), and drawCursor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ drawCursor() [2/2]

◆ endLayout()

void QTextLayout::endLayout ( )

◆ engine()

QTextEngine * QTextLayout::engine ( ) const
inline

Returns the text engine used to render the text layout.

Definition at line 173 of file qtextlayout.h.

References d.

Referenced by QQuickTextPrivate::elidedText(), QTextBlockData::invalidate(), QQuickText::invalidateFontCaches(), and QQuickTextPrivate::setupTextLayout().

+ Here is the caller graph for this function:

◆ font()

QFont QTextLayout::font ( ) const

Returns the current font that is used for the layout, or a default font if none is set.

See also
setFont()

Definition at line 405 of file qtextlayout.cpp.

References QTextEngine::font().

Referenced by QTextLayout(), QQuickTextPrivate::elidedText(), QQuickStyledTextPrivate::parseImageAttributes(), QWidgetTextControlPrivate::rectForPosition(), QQuickTextControlPrivate::rectForPosition(), setFont(), and QQuickTextPrivate::setupTextLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ formats()

QList< QTextLayout::FormatRange > QTextLayout::formats ( ) const
Since
5.6

Returns the list of additional formats supported by the text layout.

See also
setFormats(), clearFormats()

Definition at line 518 of file qtextlayout.cpp.

References QTextEngine::formats().

Referenced by QQuickTextPrivate::anchorAt(), and QQuickTextPrivate::elideFormats().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ glyphRuns()

QList< QGlyphRun > QTextLayout::glyphRuns ( int from = -1,
int length = -1,
GlyphRunRetrievalFlags flags = DefaultRetrievalFlags ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the glyph indexes and positions for all glyphs corresponding to the length characters starting at the position from in this QTextLayout.

This is an expensive function, and should not be called in a time sensitive context.

If from is less than zero, then the glyph run will begin at the first character in the layout. If length is less than zero, it will span the entire string from the start position.

The retrievalFlags specifies which properties of the QGlyphRun will be retrieved from the layout. To minimize allocations and memory consumption, this should be set to include only the properties that you need to access later.

Since
6.5
See also
draw(), QPainter::drawGlyphRun()

Definition at line 1033 of file qtextlayout.cpp.

References QList< T >::at(), boundingRect(), QRawFontPrivate::fontEngine, QScriptLine::from, QGlyphRun::glyphIndexes(), glyphRuns(), QTextLine::glyphRuns(), i, QScriptLine::length, QTextEngine::lines, positions, QString::size(), QList< T >::size(), text(), and QRectF::united().

Referenced by glyphRuns(), and QSvgVisitorImpl::visitTextNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidCursorPosition()

bool QTextLayout::isValidCursorPosition ( int pos) const

Returns true if position pos is a valid cursor position.

In a Unicode context some positions in the text are not valid cursor positions, because the position is inside a Unicode surrogate or a grapheme cluster.

A grapheme cluster is a sequence of two or more Unicode characters that form one indivisible entity on the screen. For example the latin character ‘\unicode{0xC4}’ can be represented in Unicode by two characters, ‘A’ (0x41), and the combining diaeresis (0x308). A text cursor can only validly be positioned before or after these two characters, never between them since that wouldn't make sense. In indic languages every syllable forms a grapheme cluster.

Definition at line 759 of file qtextlayout.cpp.

References QTextEngine::attributes(), QCharAttributes::graphemeBoundary, QTextEngine::layoutData, pos, QString::size(), and QTextEngine::LayoutData::string.

+ Here is the call graph for this function:

◆ leftCursorPosition()

int QTextLayout::leftCursorPosition ( int oldPos) const

Returns the cursor position to the left of oldPos, next to it.

It's dependent on the visual position of characters, after bi-directional reordering.

See also
rightCursorPosition(), previousCursorPosition()

Definition at line 737 of file qtextlayout.cpp.

References QTextCursor::Left, and QTextEngine::positionAfterVisualMovement().

Referenced by QQuickTextInputPrivate::cursorForward().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lineAt()

QTextLine QTextLayout::lineAt ( int i) const

Returns the {i}-th line of text in this text layout.

See also
lineCount(), lineForTextPosition()

Definition at line 834 of file qtextlayout.cpp.

References i, and lineCount().

Referenced by QQuickTextPrivate::anchorAt(), QPlainTextDocumentLayout::blockBoundingRect(), QCommonStylePrivate::calculateElidedText(), QQC2::QCommonStylePrivate::calculateElidedText(), QSGInternalTextNode::doAddTextLayout(), QPlainTextEditPrivate::ensureVisible(), QTextDocumentLayoutPrivate::hitTest(), QTextDocumentLayoutPrivate::layoutBlock(), lineForTextPosition(), QPlainTextEditPrivate::pageUpDown(), QQuickTextInputPrivate::positionAt(), QWidgetLineControl::rectForPos(), QQuickTextPrivate::setupTextLayout(), QQuickTextPrivate::updateSize(), QSvgVisitorImpl::visitTextNode(), and QWidgetLineControl::xToPos().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lineCount()

◆ lineForTextPosition()

QTextLine QTextLayout::lineForTextPosition ( int pos) const

Returns the line that contains the cursor position specified by pos.

See also
isValidCursorPosition(), lineAt()

Definition at line 844 of file qtextlayout.cpp.

References lineAt(), QTextEngine::lineNumberForTextPosition(), and pos.

Referenced by QQuickTextNodeEngine::addText(), QQuickTextNodeEngine::addTextBlock(), QQuickTextNodeEngine::addTextObject(), QQuickTextInputPrivate::anchorRectangle(), QSGInternalTextNode::doAddTextDocument(), QTextDocumentLayoutPrivate::drawBlock(), QPlainTextEditPrivate::ensureVisible(), QQuickTextInputPrivate::ensureVisible(), QQuickTextEdit::updatePaintNode(), and QQuickTextInputPrivate::updateVerticalScroll().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maximumWidth()

qreal QTextLayout::maximumWidth ( ) const

The maximum width the layout could expand to; this is essentially the width of the entire text.

Warning
This function only returns a valid value after the layout has been done.
See also
minimumWidth()

Definition at line 920 of file qtextlayout.cpp.

References QTextEngine::maxWidth, and QFixed::toReal().

Referenced by QTextDocumentLayoutPrivate::layoutBlock(), and QQuickTextPrivate::setupTextLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ minimumWidth()

qreal QTextLayout::minimumWidth ( ) const

The minimum width the layout needs.

This is the width of the layout's smallest non-breakable substring.

Warning
This function only returns a valid value after the layout has been done.
See also
maximumWidth()

Definition at line 906 of file qtextlayout.cpp.

References QTextEngine::minWidth, and QFixed::toReal().

Referenced by QTextDocumentLayoutPrivate::layoutBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nextCursorPosition()

int QTextLayout::nextCursorPosition ( int oldPos,
CursorMode mode = SkipCharacters ) const

Returns the next valid cursor position after oldPos that respects the given cursor mode.

Returns value of oldPos, if oldPos is not a valid cursor position.

See also
isValidCursorPosition(), previousCursorPosition()

Definition at line 650 of file qtextlayout.cpp.

References QTextEngine::attributes(), QTextEngine::atWordSeparator(), QTextEngine::block, QTextBlock::isValid(), QTextEngine::layoutData, QTextBlock::length(), Q_ASSERT, QString::size(), SkipCharacters, and QTextEngine::LayoutData::string.

Referenced by QQuickTextInputPrivate::cursorForward(), QQuickTextInputPrivate::cursorWordForward(), QWidgetLineControl::del(), QQuickTextInputPrivate::del(), QWidgetLineControl::selectWordAtPos(), and QQuickTextInputPrivate::selectWordAtPos().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ position()

QPointF QTextLayout::position ( ) const
Since
4.2

The global position of the layout. This is independent of the bounding rectangle and of the layout process.

See also
setPosition()

Definition at line 858 of file qtextlayout.cpp.

References QTextEngine::position.

Referenced by draw(), QTextDocumentLayoutPrivate::drawBlock(), drawCursor(), QTextDocumentLayoutPrivate::hitTest(), QTextDocumentLayoutPrivate::layoutBlock(), setPreeditArea(), and QQuickTextPrivate::updateSize().

+ Here is the caller graph for this function:

◆ preeditAreaPosition()

int QTextLayout::preeditAreaPosition ( ) const

Returns the position of the area in the text layout that will be processed before editing occurs.

See also
preeditAreaText()

Definition at line 480 of file qtextlayout.cpp.

References QTextEngine::preeditAreaPosition().

Referenced by QQuickTextNodeEngine::addTextBlock(), QQuickTextInputPrivate::calculateImplicitWidthForText(), QSGInternalTextNode::doAddTextLayout(), and QTextDocumentLayoutPrivate::drawBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ preeditAreaText()

QString QTextLayout::preeditAreaText ( ) const

Returns the text that is inserted in the layout before editing occurs.

See also
preeditAreaPosition()

Definition at line 490 of file qtextlayout.cpp.

References QTextEngine::preeditAreaText().

Referenced by QQuickTextNodeEngine::addTextBlock(), QQuickTextInputPrivate::calculateImplicitWidthForText(), QQuickTextEditPrivate::determineHorizontalAlignment(), QSGInternalTextNode::doAddTextLayout(), QTextDocumentLayoutPrivate::drawBlock(), QTextDocumentLayout::hitTest(), QWidgetTextControlPrivate::inputMethodEvent(), QQuickTextInputPrivate::sendMouseEventToInputContext(), QQuickTextInputPrivate::textDirection(), QQuickTextInputPrivate::updateHorizontalScroll(), and QQuickTextInputPrivate::updateVerticalScroll().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ previousCursorPosition()

int QTextLayout::previousCursorPosition ( int oldPos,
CursorMode mode = SkipCharacters ) const

Returns the first valid cursor position before oldPos that respects the given cursor mode.

Returns value of oldPos, if oldPos is not a valid cursor position.

See also
isValidCursorPosition(), nextCursorPosition()

Definition at line 686 of file qtextlayout.cpp.

References QTextEngine::attributes(), QTextEngine::atWordSeparator(), QTextEngine::block, QTextBlock::isValid(), QTextEngine::layoutData, QTextBlock::length(), Q_ASSERT, QString::size(), SkipCharacters, and QTextEngine::LayoutData::string.

Referenced by QQuickTextInputPrivate::cursorForward(), QQuickTextInputPrivate::cursorWordBackward(), QWidgetLineControl::selectWordAtPos(), and QQuickTextInputPrivate::selectWordAtPos().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rightCursorPosition()

int QTextLayout::rightCursorPosition ( int oldPos) const

Returns the cursor position to the right of oldPos, next to it.

It's dependent on the visual position of characters, after bi-directional reordering.

See also
leftCursorPosition(), nextCursorPosition()

Definition at line 723 of file qtextlayout.cpp.

References QTextEngine::positionAfterVisualMovement(), and QTextCursor::Right.

Referenced by QQuickTextInputPrivate::cursorForward().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCacheEnabled()

void QTextLayout::setCacheEnabled ( bool enable)

Enables caching of the complete layout information if enable is true; otherwise disables layout caching.

Usually QTextLayout throws most of the layouting information away after a call to endLayout() to reduce memory consumption. If you however want to draw the laid out text directly afterwards enabling caching might speed up drawing significantly.

See also
cacheEnabled()

Definition at line 545 of file qtextlayout.cpp.

References QTextEngine::cacheGlyphs.

Referenced by QStaticTextPrivate::paintText(), QQuickTextPrivate::setupTextLayout(), and src_gui_text_qtextlayout::wrapper0().

+ Here is the caller graph for this function:

◆ setCursorMoveStyle()

void QTextLayout::setCursorMoveStyle ( Qt::CursorMoveStyle style)

Sets the visual cursor movement style to the given style.

If the QTextLayout is backed by a document, you can ignore this and use the option in QTextDocument, this option is for widgets like QLineEdit or custom widgets without a QTextDocument. Default value is Qt::LogicalMoveStyle.

See also
cursorMoveStyle()

Definition at line 569 of file qtextlayout.cpp.

References QTextEngine::visualMovement, and Qt::VisualMoveStyle.

Referenced by QQuickTextInputPrivate::setCursorMoveStyle().

+ Here is the caller graph for this function:

◆ setFlags()

void QTextLayout::setFlags ( int flags)

Definition at line 929 of file qtextlayout.cpp.

References Qt::AlignJustify, QTextEngine::forceJustification, QTextEngine::ignoreBidi, Qt::LeftToRight, QTextEngine::option, Qt::RightToLeft, QTextOption::setAlignment(), QTextOption::setTextDirection(), Qt::TextForceLeftToRight, Qt::TextForceRightToLeft, and Qt::TextJustificationForced.

+ Here is the call graph for this function:

◆ setFont()

void QTextLayout::setFont ( const QFont & font)

Sets the layout's font to the given font.

The layout is invalidated and must be laid out again.

See also
font()

Definition at line 390 of file qtextlayout.cpp.

References QTextEngine::fnt, font(), QTextEngine::resetFontEngineCache(), and QTextEngine::useRawFont.

Referenced by QStaticTextPrivate::paintText(), QQuickTextPrivate::setupTextLayout(), QVideoTextureHelper::SubtitleLayout::update(), QQuickTextPrivate::updateLayout(), and QQuickTextInputPrivate::updateLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFormats()

void QTextLayout::setFormats ( const QList< FormatRange > & formats)
Since
5.6

Sets the additional formats supported by the text layout to formats. The formats are applied with preedit area text in place.

See also
formats(), clearFormats()

Definition at line 503 of file qtextlayout.cpp.

References QTextEngine::block, QTextDocumentPrivate::get(), QTextBlock::length(), QTextBlock::position(), and QTextEngine::setFormats().

Referenced by clearFormats(), QQuickStyledTextPrivate::parse(), QWidgetLineControl::processInputMethodEvent(), and QQuickTextPrivate::setupTextLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPosition()

void QTextLayout::setPosition ( const QPointF & p)

Moves the text layout to point p.

See also
position()

Definition at line 868 of file qtextlayout.cpp.

References QTextEngine::position.

Referenced by QTextDocumentLayoutPrivate::layoutBlock(), and QVideoTextureHelper::SubtitleLayout::update().

+ Here is the caller graph for this function:

◆ setPreeditArea()

void QTextLayout::setPreeditArea ( int position,
const QString & text )

Sets the position and text of the area in the layout that is processed before editing occurs.

The layout is invalidated and must be laid out again.

See also
preeditAreaPosition(), preeditAreaText()

Definition at line 464 of file qtextlayout.cpp.

References QTextEngine::block, QTextDocumentPrivate::get(), QTextBlock::length(), position(), QTextBlock::position(), QTextEngine::preeditAreaPosition(), QTextEngine::preeditAreaText(), QTextEngine::setPreeditArea(), and text().

+ Here is the call graph for this function:

◆ setRawFont()

void QTextLayout::setRawFont ( const QRawFont & rawFont)

Sets a raw font, to be used with QTextLayout::glyphRuns. Note that this only supports the needs of WebKit. Use of this function with e.g. QTextLayout::draw will result in undefined behaviour.

Definition at line 376 of file qtextlayout.cpp.

References QTextEngine::rawFont, QTextEngine::resetFontEngineCache(), and QTextEngine::useRawFont.

+ Here is the call graph for this function:

◆ setText()

void QTextLayout::setText ( const QString & string)

Sets the layout's text to the given string.

The layout is invalidated and must be laid out again.

Notice that when using this QTextLayout as part of a QTextDocument this method will have no effect.

See also
text()

Definition at line 419 of file qtextlayout.cpp.

References QTextEngine::clearLineData(), QTextEngine::invalidate(), and QTextEngine::text.

Referenced by QStaticTextPrivate::paintText(), QQuickStyledTextPrivate::parse(), QQuickTextPrivate::setupTextLayout(), QVideoTextureHelper::SubtitleLayout::update(), and QQuickTextPrivate::updateLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTextOption()

void QTextLayout::setTextOption ( const QTextOption & option)

Sets the text option structure that controls the layout process to the given option.

See also
textOption()

Definition at line 442 of file qtextlayout.cpp.

References QTextEngine::option.

Referenced by QCommonStylePrivate::calculateElidedText(), QQC2::QCommonStylePrivate::calculateElidedText(), QQuickTextInputPrivate::init(), QTextDocumentLayoutPrivate::layoutBlock(), QStaticTextPrivate::paintText(), QQuickTextPrivate::setupTextLayout(), QVideoTextureHelper::SubtitleLayout::update(), and QQuickTextInputPrivate::updateLayout().

+ Here is the caller graph for this function:

◆ text()

QString QTextLayout::text ( ) const

Returns the layout's text.

See also
setText()

Definition at line 431 of file qtextlayout.cpp.

References QTextEngine::text.

Referenced by QTextLayout(), QTextLayout(), QCommonStylePrivate::calculateElidedText(), QQC2::QCommonStylePrivate::calculateElidedText(), QVideoTextureHelper::SubtitleLayout::draw(), QQuickTextPrivate::elidedText(), glyphRuns(), setPreeditArea(), QQuickTextPrivate::setupTextLayout(), QVideoTextureHelper::SubtitleLayout::toImage(), and QVideoTextureHelper::SubtitleLayout::update().

+ Here is the caller graph for this function:

◆ textOption()

const QTextOption & QTextLayout::textOption ( ) const

Returns the current text option used to control the layout process.

See also
setTextOption()

Definition at line 452 of file qtextlayout.cpp.

References QTextEngine::option.

Referenced by QQuickTextInputPrivate::calculateImplicitWidthForText(), QQuickTextInputPrivate::init(), QTextDocumentLayoutPrivate::layoutFlow(), QQuickTextPrivate::setupTextLayout(), and QQuickTextInputPrivate::updateLayout().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QGraphicsSimpleTextItem

friend class QGraphicsSimpleTextItem
friend

Definition at line 181 of file qtextlayout.h.

◆ QGraphicsSimpleTextItemPrivate

friend class QGraphicsSimpleTextItemPrivate
friend

Definition at line 180 of file qtextlayout.h.

◆ QPainter

friend class QPainter
friend

Definition at line 179 of file qtextlayout.h.

◆ qt_format_text

void qt_format_text ( const QFont & font,
const QRectF & _r,
int tf,
const QTextOption * opt,
const QString & str,
QRectF * brect,
int tabstops,
int * tabarray,
int tabarraylen,
QPainter * painter )
friend

Definition at line 7097 of file qpainter.cpp.


The documentation for this class was generated from the following files: