Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QTextLine Class Reference

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

    #include <QTextLine>

- List of all members, including inherited members

### Public Types

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

### Public Functions

- QTextLine ()
- float ascent () const
- float cursorToX ( int * cursorPos, Edge edge = Leading ) const
- float cursorToX ( int cursorPos, Edge edge = Leading ) const
- float descent () const
- int from () const
- float height () const
- bool isValid () const
- void layout ( float width )
- void layoutFixedColumnWidth ( int numColumns )
- int length () const
- int line () const
- QRect rect () const
- void setPosition ( const QPointF & pos )
- float textWidth () const
- float width () const
- float x () const
- int xToCursor ( float x, CursorPosition cpos = CursorBetweenCharacters ) const
- float y () const

## 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 layout() function. A line has a number of attributes including the rectangle it occupies, rect(), its coordinates, x() and y(), its length(), width() and textWidth(), 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().

## Member Type Documentation

### enum QTextLine::CursorPosition

`QTextLine::CursorBetweenCharacters` |
`QTextLine::CursorOnCharacter` |

### enum QTextLine::Edge

`QTextLine::Leading` |
`QTextLine::Trailing` |

## Member Function Documentation

### QTextLine::QTextLine ()

Creates an invalid line.

### float QTextLine::ascent () const

Returns the line's ascent.

See also descent() and height().

### float 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, 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::cursorToX ( int cursorPos, Edge edge = Leading ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

### float QTextLine::descent () const

Returns the line's descent.

See also ascent() and height().

### int QTextLine::from () const

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

### float QTextLine::height () const

Returns the line's height. This is equal to ascent() + descent() + 1.

See also ascent() and descent().

### bool QTextLine::isValid () const

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

### void QTextLine::layout ( float width )

Lays out the line with the given width. The line is filled from it's starting position with as many characters as will fit into the line.

### void QTextLine::layoutFixedColumnWidth ( int numColumns )

Lays out the line. The line is filled from it's starting position with as many characters as are specified by numColumns.

### int QTextLine::length () const

Returns the length of the text in the line.

See also textWidth().

### int QTextLine::line () const

Returns the position of the line in the text engine.

### QRect QTextLine::rect () const

Returns the line's bounding rectangle.

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

### void QTextLine::setPosition ( const QPointF & pos )

Moves the line to position pos.

### float QTextLine::textWidth () 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.

### float QTextLine::width () const

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

See also textWidth(), x(), y(), length(), and rect().

### float QTextLine::x () const

Returns the line's x position.

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

### int QTextLine::xToCursor ( float x, CursorPosition cpos = CursorBetweenCharacters ) const

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

See also cursorToX().

### float QTextLine::y () const

Returns the line's y position.

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