CopperSpice API  1.7.4
QTextLine Class Reference

The QTextLine class represents a line of text inside a QTextLayout. More...

## Public Types

enum  CursorPosition

enum  Edge

## Public Methods

QTextLine ()

qreal ascent () const

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

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

qreal descent () const

void draw (QPainter *painter, const QPointF &point, const QTextLayout::FormatRange *selection=nullptr) const

QList< QGlyphRunglyphRuns (int from=-1, int length=-1) const

qreal height () const

bool isValid () const

int lineNumber () const

QRectF naturalTextRect () const

qreal naturalTextWidth () const

QPointF position () const

QRectF rect () const

void setLineWidth (qreal width)

void setNumColumns (int columns, std::optional< qreal > alignmentWidth=std::optional< qreal >())

void setPosition (const QPointF &point)

int textLength () const

int textStart () const

qreal width () const

qreal x () const

int xToCursor (qreal x, CursorPosition cursorPos=CursorBetweenCharacters) const

qreal y () const

## Friends

class QTextFragment

class QTextLayout

## Detailed Description

The QTextLine class represents a line of text inside a QTextLayout.

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 decent() 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().

descent(), height()

## Member Enumeration Documentation

ConstantValue
QTextLine::CursorBetweenCharacters0
QTextLine::CursorOnCharacter1
 enum QTextLine::Edge
ConstantValue
QTextLine::Leading0
QTextLine::Trailing1

## Constructor & Destructor Documentation

 QTextLine::QTextLine ( )
inline

Creates an invalid line.

## Method Documentation

 qreal QTextLine::ascent ( ) const

Returns the line's ascent.

descent(), height()
 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 then the nearest valid cursor position will be used. The cursorPos will be modified to point to this valid cursor position.

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

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

 qreal QTextLine::descent ( ) const

Returns the line's descent.

ascent(), height()
 void QTextLine::draw ( QPainter * painter, const QPointF & point, const QTextLayout::FormatRange * selection = nullptr ) const

Draws a line on the given painter at the specified point. The selection is reserved for internal use.

 QList< QGlyphRun > QTextLine::glyphRuns ( int from = -1, int length = -1 ) 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().

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

QTextLayout::glyphRuns()
 qreal QTextLine::height ( ) const

Returns the line's height. This is equal to ascent() + descent() + 1 if leading is not included. If leading is included, this equals to ascent() + descent() + leading() + 1.

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.

 bool QTextLine::isValid ( ) const
inline

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

ascent(), descent(), height()

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

By default, leading is not included.

 int QTextLine::lineNumber ( ) const
inline

Returns the position of the line in the text engine.

 QRectF QTextLine::naturalTextRect ( ) const

Returns the rectangle covered by the line.

 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.

 QPointF QTextLine::position ( ) const

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

setPosition()
 QRectF QTextLine::rect ( ) const

Returns the line's bounding rectangle.

x(), y(), textLength(), width()
 void QTextLine::setLeadingIncluded ( bool included )

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

Negative leading is ignored and it must be handled in the code using the text lines by letting the lines overlap.

 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 can not be split at the end of the line, it will be filled with additional characters to the next whitespace or end of the text.

 void QTextLine::setNumColumns ( int columns, std::optional< qreal > alignmentWidth = std::optional() )

Lays out the line by filling from the starting position using the number of characters specified by columns.

In case the text can not be split until numColumns characters, the line will be filled with as many characters to the next whitespace or end of the text. The given alignmentWidth is used as reference width for alignment.

 void QTextLine::setPosition ( const QPointF & point )

Moves the line to position point.

position()
 int QTextLine::textLength ( ) const

Returns the length of the text in the line.

naturalTextWidth()
 int QTextLine::textStart ( ) const

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

 qreal QTextLine::width ( ) const

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

naturalTextWidth(), x(), y(), textLength(), rect()
 qreal QTextLine::x ( ) const

Returns the line's x position.

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