|  | Home · All Classes · Modules

# QTextLine Class Reference
[QtGui module]

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

### Types

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

### Methods

- __init__ (self)
- __init__ (self, QTextLine)
- float ascent (self)
- (float, int) cursorToX (self, int, Edge edge = QTextLine.Leading)
- float descent (self)
- draw (self, QPainter, QPointF, QTextLayout.FormatRange selection = None)
- float height (self)
- bool isValid (self)
- float leading (self)
- bool leadingIncluded (self)
- int lineNumber (self)
- QRectF naturalTextRect (self)
- float naturalTextWidth (self)
- QPointF position (self)
- QRectF rect (self)
- setLeadingIncluded (self, bool)
- setLineWidth (self, float)
- setNumColumns (self, int)
- setNumColumns (self, int, float)
- setPosition (self, QPointF)
- int textLength (self)
- int textStart (self)
- float width (self)
- float x (self)
- int xToCursor (self, float, CursorPosition edge = QTextLine.CursorBetweenCharacters)
- float y (self)

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

## Type Documentation

### QTextLine.CursorPosition

Constant | Value
--- | ---
`QTextLine.CursorBetweenCharacters` | `0`
`QTextLine.CursorOnCharacter` | `1`

### QTextLine.Edge

Constant | Value
--- | ---
`QTextLine.Leading` | `0`
`QTextLine.Trailing` | `1`

## Method Documentation

### QTextLine.__init__ (self)

Creates an invalid line.

### QTextLine.__init__ (self, QTextLine)

### float QTextLine.ascent (self)

Returns the line's ascent.

See also descent() and height().

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

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

See also xToCursor().

### float QTextLine.descent (self)

Returns the line's descent.

See also ascent() and height().

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

Draws a line on the given painter at the specified position. The 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.

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

### bool QTextLine.isValid (self)

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

### float QTextLine.leading (self)

Returns the line's leading.

This function was introduced in Qt 4.6.

See also ascent(), descent(), and 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.

This function was introduced in Qt 4.6.

See also 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.

See also setPosition().

### QRectF QTextLine.rect (self)

Returns the line's bounding rectangle.

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

### QTextLine.setLeadingIncluded (self, bool)

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.

This function was introduced in Qt 4.6.

See also leadingIncluded().

### QTextLine.setLineWidth (self, float)

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)

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.

### QTextLine.setNumColumns (self, int, float)

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.

### QTextLine.setPosition (self, QPointF)

Moves the line to position pos.

See also position().

### int QTextLine.textLength (self)

Returns the length of the text in the line.

See also 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() function.

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

### float QTextLine.x (self)

Returns the line's x position.

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

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

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

See also cursorToX().

### float QTextLine.y (self)

Returns the line's y position.

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