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
QTextLine Class Reference

\reentrant More...

#include <qtextlayout.h>

+ Collaboration diagram for QTextLine:

Public Types

enum  Edge { Leading , Trailing }
 \value Leading \value Trailing More...
 
enum  CursorPosition { CursorBetweenCharacters , CursorOnCharacter }
 \value CursorBetweenCharacters \value CursorOnCharacter More...
 

Public Member Functions

 QTextLine ()
 Creates an invalid line.
 
bool isValid () const
 Returns true if this text line is valid; otherwise returns false.
 
QRectF rect () const
 Returns the line's bounding rectangle.
 
qreal x () const
 Returns the line's x position.
 
qreal y () const
 Returns the line's y position.
 
qreal width () const
 Returns the line's width as specified by the layout() function.
 
qreal ascent () const
 Returns the line's ascent.
 
qreal descent () const
 Returns the line's descent.
 
qreal height () const
 Returns the line's height.
 
qreal leading () const
 
void setLeadingIncluded (bool included)
 
bool leadingIncluded () const
 
qreal naturalTextWidth () const
 Returns the width of the line that is occupied by text.
 
qreal horizontalAdvance () const
 
QRectF naturalTextRect () const
 Returns the rectangle covered by the line.
 
qreal cursorToX (int *cursorPos, Edge edge=Leading) const
 Converts the cursor position cursorPos to the corresponding x position inside the line, taking account of the edge.
 
qreal cursorToX (int cursorPos, Edge edge=Leading) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
int xToCursor (qreal x, CursorPosition=CursorBetweenCharacters) const
 Converts the x-coordinate x, to the nearest matching cursor position, depending on the cursor position type, cpos.
 
void setLineWidth (qreal width)
 Lays out the line with the given width.
 
void setNumColumns (int columns)
 Lays out the line.
 
void setNumColumns (int columns, qreal alignmentWidth)
 Lays out the line.
 
void setPosition (const QPointF &pos)
 Moves the line to position pos.
 
QPointF position () const
 Returns the line's position relative to the text layout's position.
 
int textStart () const
 Returns the start of the line from the beginning of the string passed to the QTextLayout.
 
int textLength () const
 Returns the length of the text in the line.
 
int lineNumber () const
 Returns the position of the line in the text engine.
 
void draw (QPainter *painter, const QPointF &position) const
 Draws a line on the given painter at the specified position.
 
QList< QGlyphRunglyphRuns (int from=-1, int length=-1, QTextLayout::GlyphRunRetrievalFlags flags=QTextLayout::DefaultRetrievalFlags) const
 Returns the glyph indexes and positions for all glyphs in this QTextLine for characters in the range defined by from and length.
 

Friends

class QTextLayout
 
class QTextFragment
 

Detailed Description

\reentrant

The QTextLine class represents a line of text inside a QTextLayout. \inmodule QtGui

A text line is usually created by QTextLayout::createLine().

After being created, the line can be filled using the setLineWidth() or setNumColumns() functions. A line has a number of attributes including the rectangle it occupies, rect(), its coordinates, x() and y(), its textLength(), width() and naturalTextWidth(), and its ascent() and descent() relative to the text. The position of the cursor in terms of the line is available from cursorToX() and its inverse from xToCursor(). A line can be moved with setPosition().

Definition at line 190 of file qtextlayout.h.

Member Enumeration Documentation

◆ CursorPosition

\value CursorBetweenCharacters \value CursorOnCharacter

Enumerator
CursorBetweenCharacters 
CursorOnCharacter 

Definition at line 216 of file qtextlayout.h.

◆ Edge

\value Leading \value Trailing

Enumerator
Leading 
Trailing 

Definition at line 212 of file qtextlayout.h.

Constructor & Destructor Documentation

◆ QTextLine()

QTextLine::QTextLine ( )
inline

Creates an invalid line.

Definition at line 193 of file qtextlayout.h.

Member Function Documentation

◆ ascent()

qreal QTextLine::ascent ( ) const

Returns the line's ascent.

See also
descent(), height()

Definition at line 1501 of file qtextlayout.cpp.

References QScriptLine::ascent, QList< T >::at(), QTextEngine::lines, and QFixed::toReal().

Referenced by QQuickTextNodeEngine::addImage(), QQuickTextPrivate::updateSize(), and QSvgVisitorImpl::visitTextNode().

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

◆ cursorToX() [1/2]

qreal QTextLine::cursorToX ( int * cursorPos,
Edge edge = Leading ) const

Converts the cursor position cursorPos to the corresponding x position inside the line, taking account of the edge.

If cursorPos is not a valid cursor position, the nearest valid cursor position will be used instead, and cursorPos will be modified to point to this valid cursor position.

See also
xToCursor()

Definition at line 2896 of file qtextlayout.cpp.

References QScriptItem::analysis, QGlyphLayout::attributes, QScriptAnalysis::bidiLevel, QTextEngine::bidiReorder(), QGlyphAttributes::clusterStart, QGlyphLayout::effectiveAdvance(), QScriptAnalysis::flags, QString::from, i, item, QString::length(), line, QTextOption::NoWrap, QScriptItem::num_glyphs, pos, QScriptItem::position, Q_ASSERT, qBound(), qMax(), qMin(), QString::size(), QScriptAnalysis::TabOrObject, and QScriptItem::width.

Referenced by QQuickTextInputPrivate::anchorRectangle(), QQuickTextInput::cursorRectangle(), QTextLayout::drawCursor(), QQuickTextInputPrivate::ensureVisible(), QQuickTextInput::positionToRectangle(), and QWidgetLineControl::rectForPos().

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

◆ cursorToX() [2/2]

int QTextLine::cursorToX ( int cursorPos,
Edge edge = Leading ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 223 of file qtextlayout.h.

References cursorToX().

Referenced by cursorToX().

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

◆ descent()

qreal QTextLine::descent ( ) const

Returns the line's descent.

See also
ascent(), height()

Definition at line 1511 of file qtextlayout.cpp.

References QList< T >::at(), QScriptLine::descent, QTextEngine::lines, and QFixed::toReal().

+ Here is the call graph for this function:

◆ draw()

void QTextLine::draw ( QPainter * painter,
const QPointF & position ) const

Draws a line on the given painter at the specified position.

Definition at line 2621 of file qtextlayout.cpp.

References painter, and position().

Referenced by QTextLayout::draw().

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

◆ glyphRuns()

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

Returns the glyph indexes and positions for all glyphs in this QTextLine for characters in the range defined by from and length.

The from index is relative to the beginning of the text in the containing QTextLayout, and the range must be within the range of QTextLine as given by functions textStart() and textLength().

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.

If from is negative, it will default to textStart(), and if length is negative it will default to the return value of textLength().

Since
6.5
See also
QTextLayout::glyphRuns()

Definition at line 2414 of file qtextlayout.cpp.

References QGlyphLayout::advances, QScriptItem::analysis, QString::at(), QGlyphLayout::attributes, QScriptAnalysis::bidiLevel, QGlyphAttributes::dontPrint, QFontPrivate::engineForScript(), QScriptAnalysis::flags, font, QFixed::fromFixed(), glyphRunWithInfo(), QGlyphLayout::glyphs, i, QGlyphRun::isEmpty(), QGlyphLayout::justifications, QString::length(), QList< T >::length(), line, QGlyphLayout::mid(), QFontEngine::Multi, QScriptItem::num_glyphs, QGlyphLayout::numGlyphs, QFont::overline(), QGlyphRun::Overline, pos, QScriptItem::position, qMax(), qMin(), QGlyphRun::RightToLeft, QScriptAnalysis::script, selection, QGlyphJustification::space_18d6, QGlyphRun::SplitLigature, QFont::strikeOut(), QGlyphRun::StrikeOut, QScriptAnalysis::TabOrObject, QFont::underline(), and QGlyphRun::Underline.

Referenced by QTextFragment::glyphRuns(), and QTextLayout::glyphRuns().

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

◆ height()

qreal QTextLine::height ( ) const

Returns the line's height.

This is equal to ascent() + descent() if leading is not included. If leading is included, this equals to ascent() + descent() + leading().

See also
ascent(), descent(), leading(), setLeadingIncluded()

Definition at line 1523 of file qtextlayout.cpp.

References QList< T >::at(), QFixed::ceil(), QScriptLine::height(), and QTextEngine::lines.

Referenced by QQuickTextInputPrivate::anchorRectangle(), QCommonStylePrivate::calculateElidedText(), QQC2::QCommonStylePrivate::calculateElidedText(), QQuickTextInput::cursorRectangle(), QQuickTextLine::height(), QQuickTextInput::positionToRectangle(), QWidgetLineControl::rectForPos(), and QQuickTextLine::setHeight().

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

◆ horizontalAdvance()

qreal QTextLine::horizontalAdvance ( ) const
Since
4.7 Returns the horizontal advance of the text. The advance of the text is the distance from its position to the next position at which text would naturally be drawn.

By adding the advance to the position of the text line and using this as the position of a second text line, you will be able to position the two lines side-by-side without gaps in-between.

Definition at line 1595 of file qtextlayout.cpp.

References QList< T >::at(), QTextEngine::lines, QScriptLine::textAdvance, and QFixed::toReal().

+ Here is the call graph for this function:

◆ isValid()

bool QTextLine::isValid ( ) const
inline

Returns true if this text line is valid; otherwise returns false.

Definition at line 194 of file qtextlayout.h.

Referenced by QQuickTextNodeEngine::addToSceneGraph(), QQuickTextInputPrivate::anchorRectangle(), QQuickTextInput::cursorRectangle(), QQuickTextInputPrivate::ensureVisible(), QQuickTextInput::positionToRectangle(), QQuickTextNodeEngine::setCurrentLine(), QQuickTextInputPrivate::updateVerticalScroll(), viewItemTextLayout(), QQC2::viewItemTextLayout(), and QSvgVisitorImpl::visitTextNode().

+ Here is the caller graph for this function:

◆ leading()

qreal QTextLine::leading ( ) const
Since
4.6

Returns the line's leading.

See also
ascent(), descent(), height()

Definition at line 1535 of file qtextlayout.cpp.

References QList< T >::at(), QScriptLine::leading, QTextEngine::lines, and QFixed::toReal().

+ Here is the call graph for this function:

◆ leadingIncluded()

bool QTextLine::leadingIncluded ( ) const
Since
4.6

Returns true if positive leading is included into the line's height; otherwise returns false.

By default, leading is not included.

See also
setLeadingIncluded()

Definition at line 1570 of file qtextlayout.cpp.

References QList< T >::at(), QScriptLine::leadingIncluded, and QTextEngine::lines.

+ Here is the call graph for this function:

◆ lineNumber()

int QTextLine::lineNumber ( ) const
inline

Returns the position of the line in the text engine.

Definition at line 236 of file qtextlayout.h.

Referenced by QQuickTextLine::number(), and QWidgetTextControl::selectionRect().

+ Here is the caller graph for this function:

◆ naturalTextRect()

QRectF QTextLine::naturalTextRect ( ) const

Returns the rectangle covered by the line.

Definition at line 1453 of file qtextlayout.cpp.

References QTextEngine::alignLine(), QList< T >::at(), and QTextEngine::lines.

Referenced by QTextLayout::draw(), QPlainTextEditPrivate::ensureVisible(), and QPlainTextEditPrivate::pageUpDown().

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

◆ naturalTextWidth()

qreal QTextLine::naturalTextWidth ( ) const

Returns the width of the line that is occupied by text.

This is always <= to width(), and is the minimum width that could be used by layout() without changing the line break position.

Definition at line 1580 of file qtextlayout.cpp.

References QList< T >::at(), QTextEngine::lines, QScriptLine::textWidth, and QFixed::toReal().

Referenced by QPlainTextDocumentLayout::blockBoundingRect(), QQuickTextInputPrivate::ensureVisible(), QQuickTextLine::implicitWidth(), QQuickTextLine::isLast(), QTextDocumentLayoutPrivate::layoutBlock(), and QTextDocumentLayoutPrivate::positionFloat().

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

◆ position()

QPointF QTextLine::position ( ) const

Returns the line's position relative to the text layout's position.

Definition at line 2191 of file qtextlayout.cpp.

Referenced by QQuickTextNodeEngine::addImage().

+ Here is the caller graph for this function:

◆ rect()

QRectF QTextLine::rect ( ) const

Returns the line's bounding rectangle.

See also
x(), y(), textLength(), width()

Definition at line 1444 of file qtextlayout.cpp.

References QList< T >::at(), and QTextEngine::lines.

Referenced by QQuickTextNodeEngine::addImage(), QTextLayout::draw(), and QQuickTextInputPrivate::updateVerticalScroll().

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

◆ setLeadingIncluded()

void QTextLine::setLeadingIncluded ( bool included)
Since
4.6

Includes positive leading into the line's height if included is true; otherwise does not include leading.

By default, leading is not included.

Note that negative leading is ignored, it must be handled in the code using the text lines by letting the lines overlap.

See also
leadingIncluded()

Definition at line 1554 of file qtextlayout.cpp.

References QTextEngine::lines.

◆ setLineWidth()

void QTextLine::setLineWidth ( qreal width)

Lays out the line with the given width.

The line is filled from its starting position with as many characters as will fit into the line. In case the text cannot be split at the end of the line, it will be filled with additional characters to the next whitespace or end of the text.

Definition at line 1607 of file qtextlayout.cpp.

References QString::from, QFixed::fromReal(), QTextEngine::layoutData, QString::length(), line, QTextEngine::lines, qBound(), QFIXED_MAX, qWarning, QString::size(), and QTextEngine::LayoutData::string.

Referenced by QQuickTextLine::setWidth().

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

◆ setNumColumns() [1/2]

void QTextLine::setNumColumns ( int numColumns)

Lays out the line.

The line is filled from its starting position with as many characters as are specified by numColumns. In case the text cannot be split until numColumns characters, the line will be filled with as many characters to the next whitespace or end of the text.

Definition at line 1635 of file qtextlayout.cpp.

References QString::length(), line, QTextEngine::lines, and QFIXED_MAX.

Referenced by QTextLayout::createLine(), and QTextLayout::endLayout().

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

◆ setNumColumns() [2/2]

void QTextLine::setNumColumns ( int numColumns,
qreal alignmentWidth )

Lays out the line.

The line is filled from its starting position with as many characters as are specified by numColumns. In case the text cannot be split until numColumns characters, the line will be filled with as many characters to the next whitespace or end of the text. The provided alignmentWidth is used as reference width for alignment.

Definition at line 1652 of file qtextlayout.cpp.

References QFixed::fromReal(), QString::length(), line, QTextEngine::lines, qBound(), and QFIXED_MAX.

+ Here is the call graph for this function:

◆ setPosition()

void QTextLine::setPosition ( const QPointF & pos)

Moves the line to position pos.

Definition at line 2182 of file qtextlayout.cpp.

References QFixed::fromReal(), and pos.

Referenced by QQuickTextLine::setHeight(), QQuickTextPrivate::setupTextLayout(), QQuickTextLine::setX(), and QQuickTextLine::setY().

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

◆ textLength()

int QTextLine::textLength ( ) const

Returns the length of the text in the line.

See also
naturalTextWidth()

Definition at line 2217 of file qtextlayout.cpp.

References QTextOption::ShowLineAndParagraphSeparators.

Referenced by QTextDocumentLayoutPrivate::drawBlock(), QQuickTextLine::isLast(), and QPlainTextEdit::paintEvent().

+ Here is the caller graph for this function:

◆ textStart()

int QTextLine::textStart ( ) const

Returns the start of the line from the beginning of the string passed to the QTextLayout.

Definition at line 2207 of file qtextlayout.cpp.

Referenced by QTextDocumentLayoutPrivate::drawBlock(), QQuickTextLine::isLast(), and QPlainTextEdit::paintEvent().

+ Here is the caller graph for this function:

◆ width()

qreal QTextLine::width ( ) const

Returns the line's width as specified by the layout() function.

See also
naturalTextWidth(), x(), y(), textLength(), rect()

Definition at line 1490 of file qtextlayout.cpp.

References QList< T >::at(), QTextEngine::lines, QFixed::toReal(), and QScriptLine::width.

Referenced by QQuickTextLine::isLast(), and QQuickTextLine::width().

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

◆ x()

qreal QTextLine::x ( ) const

Returns the line's x position.

See also
rect(), y(), textLength(), width()

Definition at line 1470 of file qtextlayout.cpp.

References QList< T >::at(), QTextEngine::lines, QFixed::toReal(), and QScriptLine::x.

Referenced by QQuickTextLine::setHeight(), QQuickTextLine::setY(), and QQuickTextLine::x().

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

◆ xToCursor()

int QTextLine::xToCursor ( qreal x,
CursorPosition cpos = CursorBetweenCharacters ) const

Converts the x-coordinate x, to the nearest matching cursor position, depending on the cursor position type, cpos.

Note that result cursor position includes possible preedit area text.

See also
cursorToX()

Definition at line 3058 of file qtextlayout.cpp.

References QScriptItem::analysis, QGlyphLayout::attributes, QScriptAnalysis::bidiLevel, QTextEngine::bidiReorder(), QGlyphAttributes::clusterStart, CursorOnCharacter, dist(), QGlyphLayout::effectiveAdvance(), QScriptAnalysis::flags, QString::from, QFixed::fromReal(), i, item, line, QScriptItem::num_glyphs, pos, QScriptItem::position, Q_ASSERT, qAbs(), qMax(), qMin(), QString::size(), QScriptAnalysis::TabOrObject, and QScriptItem::width.

Referenced by QWidgetLineControl::xToPos().

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

◆ y()

qreal QTextLine::y ( ) const

Returns the line's y position.

See also
x(), rect(), textLength(), width()

Definition at line 1480 of file qtextlayout.cpp.

References QList< T >::at(), QTextEngine::lines, QFixed::toReal(), and QScriptLine::y.

Referenced by QQuickTextInputPrivate::anchorRectangle(), QQuickTextInput::cursorRectangle(), QQuickTextInput::positionToRectangle(), QQuickTextLine::setHeight(), QQuickTextLine::setX(), and QQuickTextLine::y().

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

Friends And Related Symbol Documentation

◆ QTextFragment

friend class QTextFragment
friend

Definition at line 258 of file qtextlayout.h.

◆ QTextLayout

friend class QTextLayout
friend

Definition at line 257 of file qtextlayout.h.


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