QTextLine Class Reference

[ QtGui module]

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

类型

方法


详细描述

QTextLine 类表示一行文本在 QTextLayout .

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 (), its textLength (), width () 和 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 ().


类型文档编制

QTextLine.CursorPosition

常量
QTextLine.CursorBetweenCharacters 0
QTextLine.CursorOnCharacter 1

QTextLine.Edge

常量
QTextLine.Leading 0
QTextLine.Trailing 1

方法文档编制

QTextLine.__init__ ( self )

Creates an invalid line.

QTextLine.__init__ ( self , QTextLine )

float QTextLine.ascent ( self )

Returns the line's ascent.

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

(float, int  cursorPos ) QTextLine.cursorToX ( self , int  cursorPos , Edge   edge  = QTextLine.Leading)

Converts the cursor position cursorPos 到 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 cpos will be modified to point to this valid cursor position.

另请参阅 xToCursor ().

float QTextLine.descent ( self )

Returns the line's descent.

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

QTextLine.draw ( self , QPainter   painter , QPointF   position , QTextLayout.FormatRange   selection  = None)

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

float QTextLine.height ( self )

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.

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

float QTextLine.horizontalAdvance ( self )

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.

该函数在 Qt 4.7 引入。

bool QTextLine.isValid ( self )

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

float QTextLine.leading ( self )

Returns the line's leading.

该函数在 Qt 4.6 引入。

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

bool QTextLine.leadingIncluded ( self )

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

By default, leading is not included.

该函数在 Qt 4.6 引入。

另请参阅 setLeadingIncluded ().

int QTextLine.lineNumber ( self )

Returns the position of the line in the text engine.

QRectF QTextLine.naturalTextRect ( self )

Returns the rectangle covered by the line.

float QTextLine.naturalTextWidth ( self )

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

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

另请参阅 setPosition ().

QRectF QTextLine.rect ( self )

Returns the line's bounding rectangle.

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

QTextLine.setLeadingIncluded ( self , 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.

该函数在 Qt 4.6 引入。

另请参阅 leadingIncluded ().

QTextLine.setLineWidth ( self , float  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.

QTextLine.setNumColumns ( self , int  columns )

Lays out the line. The line is filled from its starting position with as many characters as are specified by numColumns 。在 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.

QTextLine.setNumColumns ( self , int  columns , float  alignmentWidth )

Lays out the line. The line is filled from its starting position with as many characters as are specified by numColumns 。在 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.

QTextLine.setPosition ( self , QPointF   pos )

Moves the line to position pos .

另请参阅 position ().

int QTextLine.textLength ( self )

Returns the length of the text in the line.

另请参阅 naturalTextWidth ().

int QTextLine.textStart ( self )

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

float QTextLine.width ( self )

Returns the line's width as specified by the layout() 函数。

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

float QTextLine.x ( self )

Returns the line's x position.

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

int QTextLine.xToCursor ( self , float  x , CursorPosition   edge  = QTextLine.CursorBetweenCharacters)

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

另请参阅 cursorToX ().

float QTextLine.y ( self )

Returns the line's y position.

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