QTextLine 类

QTextLine 类表示一行文本在 QTextLayout . 更多...

头: #include <QTextLine>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui

注意: 此类的所有函数 可重入 .

公共类型

enum CursorPosition { CursorBetweenCharacters, CursorOnCharacter }
enum Edge { Leading, Trailing }

公共函数

QTextLine ()
qreal ascent () const
qreal cursorToX (int * cursorPos , QTextLine::Edge edge = Leading) const
qreal cursorToX (int cursorPos , QTextLine::Edge edge = Leading) const
qreal descent () const
void draw (QPainter * painter , const QPointF & position ) const
QList<QGlyphRun> glyphRuns (int from , int length , QTextLayout::GlyphRunRetrievalFlags retrievalFlags ) const
QList<QGlyphRun> glyphRuns (int from = -1, int length = -1) const
qreal height () const
qreal horizontalAdvance () const
bool isValid () const
qreal leading () const
bool leadingIncluded () const
int lineNumber () const
QRectF naturalTextRect () const
qreal naturalTextWidth () const
QPointF position () const
QRectF rect () const
void setLeadingIncluded (bool included )
void setLineWidth (qreal width )
void setNumColumns (int numColumns )
void setNumColumns (int numColumns , qreal alignmentWidth )
void setPosition (const QPointF & pos )
int textLength () const
int textStart () const
qreal width () const
qreal x () const
int xToCursor (qreal x , QTextLine::CursorPosition cpos = CursorBetweenCharacters) const
qreal y () const

详细描述

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

After being created, the line can be filled using the setLineWidth () 或 setNumColumns () functions. A line has a number of attributes including the rectangle it occupies, rect (), its coordinates, x () 和 y (),其 textLength (), width () 和 naturalTextWidth (),及其 ascent () 和 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 ().

成员类型文档编制

enum QTextLine:: CursorPosition

常量
QTextLine::CursorBetweenCharacters 0
QTextLine::CursorOnCharacter 1

enum QTextLine:: Edge

常量
QTextLine::Leading 0
QTextLine::Trailing 1

成员函数文档编制

QTextLine:: QTextLine ()

Creates an invalid line.

qreal QTextLine:: ascent () const

Returns the line's ascent.

另请参阅 descent () 和 height ().

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

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

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.

另请参阅 xToCursor ().

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

这是重载函数。

qreal QTextLine:: descent () const

Returns the line's descent.

另请参阅 ascent () 和 height ().

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

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

[since 6.5] QList < QGlyphRun > QTextLine:: glyphRuns ( int from , int length , QTextLayout::GlyphRunRetrievalFlags retrievalFlags ) const

Returns the glyph indexes and positions for all glyphs in this QTextLine for characters in the range defined by from and lengthfrom 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 () 和 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.

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

该函数在 Qt 6.5 引入。

另请参阅 QTextLayout::glyphRuns ().

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 lengthfrom 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 () 和 textLength ().

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

注意: This is equivalent to calling glyphRuns(from, length, QTextLayout::GlyphRunRetrievalFlag::GlyphIndexes | QTextLayout::GlyphRunRetrievalFlag::GlyphPositions).

另请参阅 QTextLayout::glyphRuns ().

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

另请参阅 ascent (), descent (), leading (),和 setLeadingIncluded ().

qreal QTextLine:: horizontalAdvance () const

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

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

qreal QTextLine:: leading () const

Returns the line's leading.

另请参阅 ascent (), descent (),和 height ().

bool QTextLine:: leadingIncluded () const

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

By default, leading is not included.

另请参阅 setLeadingIncluded ().

int QTextLine:: lineNumber () const

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.

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

另请参阅 leadingIncluded ().

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.

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.

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.

void QTextLine:: setPosition (const QPointF & pos )

Moves the line to position pos .

另请参阅 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() function.

另请参阅 naturalTextWidth (), x (), y (), textLength (),和 rect ().

qreal QTextLine:: x () const

Returns the line's x position.

另请参阅 rect (), y (), textLength (),和 width ().

int QTextLine:: xToCursor ( qreal x , QTextLine::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.

另请参阅 cursorToX ().

qreal QTextLine:: y () const

Returns the line's y position.

另请参阅 x (), rect (), textLength (),和 width ().