6.0.0-rc4Source

QTextLine Class

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

Header#include <QTextLine>
CMaketarget_link_libraries(app PRIVATE Nt::Gui)
ModuleNt GUI C++ Classes

List of all members, including inherited members

Public Types

enumEdge

Public Functions

QTextLine()
boolisValid() const
QRectFrect() const
qrealx() const
qrealy() const
qrealwidth() const
qrealascent() const
qrealdescent() const
qrealheight() const
qrealleading() const
qrealnaturalTextWidth() const
QRectFnaturalTextRect() const
voidsetLineWidth(qreal width)
voidsetPosition(const QPointF &pos)
QPointFposition() const
inttextStart() const
inttextLength() const
intlineNumber() const
qrealcursorToX(int cursorPos, Edge edge = Leading) const
intxToCursor(qreal x) const
voiddraw(QPainter *painter, const QPointF &position) const

Detailed Description

A line is made by QTextLayout::createLine(). setLineWidth() gives it its width, which decides how much of the text it takes, and setPosition() places it. Afterwards the line tells its size, the part of the text that it has, and where a cursor position is on it (cursorToX() and xToCursor()).

A QTextLine refers to its layout: it is valid for as long as the layout is, and until the layout is laid out anew.

See also QTextLayout.

Differences from Qt

There is no setNumColumns(), no glyphRuns() and no setting for the leading: a line is as high as the tallest font on it. Positions are whole pixels, as Nt draws text at whole pixels.

Member Type Documentation

enum QTextLine::Edge

The edges of a character, for cursorToX().

ConstantDescription
QTextLine::LeadingThe edge where the character starts.
QTextLine::TrailingThe edge where it ends.

Member Function Documentation

QTextLine::QTextLine()

Constructs an invalid line. Valid lines come from QTextLayout::createLine() and QTextLayout::lineAt().

qreal QTextLine::ascent() const

Returns how far the line reaches above its baseline: the ascent of the tallest font on it.

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

Returns the horizontal position, in the layout, of the cursor position cursorPos of the text: the left edge of the character there, or its right edge with edge Trailing. A position outside of the line gives the start or the end of the line.

See also xToCursor().

qreal QTextLine::descent() const

Returns how far the line reaches below its baseline.

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

Draws the line with painter, with the layout at position.

qreal QTextLine::height() const

Returns the height of the line: its ascent and its descent.

bool QTextLine::isValid() const

Returns true if this is a line of a layout; otherwise returns false. QTextLayout::createLine() returns an invalid line when all the text is in lines.

qreal QTextLine::leading() const

Returns the leading of the line, which is always 0.

int QTextLine::lineNumber() const

Returns the position of the line among the lines of its layout, counted from 0.

QRectF QTextLine::naturalTextRect() const

Returns the rectangle that the text of the line takes: where the alignment puts it inside rect().

qreal QTextLine::naturalTextWidth() const

Returns the width of the text on the line, without the spaces at its end. It is more than width() if the line has a word that does not fit.

See also width().

QPointF QTextLine::position() const

Returns the position of the top left corner of the line in its layout.

See also setPosition().

QRectF QTextLine::rect() const

Returns the rectangle of the line: its position, its width as it was set, and its height.

See also naturalTextRect().

void QTextLine::setLineWidth(qreal width)

Lays the line out to the width width: the line takes the text from where the line before it ended up to what fits, or up to the next line break. Call this for each line right after QTextLayout::createLine().

See also naturalTextWidth() and textLength().

void QTextLine::setPosition(const QPointF &pos)

Places the top left corner of the line at pos, in the coordinates of its layout.

See also position().

int QTextLine::textLength() const

Returns the number of characters of the line, with the spaces and the line break at its end.

See also textStart().

int QTextLine::textStart() const

Returns the position in the text of the layout where the line starts.

See also textLength().

qreal QTextLine::width() const

Returns the width of the line, as setLineWidth() set it.

See also naturalTextWidth().

qreal QTextLine::x() const

Returns the horizontal position of the line in its layout.

See also setPosition().

int QTextLine::xToCursor(qreal x) const

Returns the cursor position of the text that is nearest to the horizontal position x of the layout: between the two characters whose border is closest.

See also cursorToX().

qreal QTextLine::y() const

Returns the vertical position of the top of the line in its layout.

See also setPosition().