
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQTextLine class represents a line of text inside aQTextLayout.More...
| Header: | #include <QTextLine> |
Note: All functions in this class arereentrant.
| enum | CursorPosition { CursorBetweenCharacters, CursorOnCharacter } |
| enum | Edge { Leading, Trailing } |
| QTextLine() | |
| qreal | ascent() const |
| qreal | cursorToX(int * cursorPos, Edge edge = Leading) const |
| qreal | cursorToX(int cursorPos, Edge edge = Leading) const |
| qreal | descent() const |
| void | draw(QPainter * painter, const QPointF & position, const QTextLayout::FormatRange * selection = 0) 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, CursorPosition cpos = CursorBetweenCharacters) const |
| qreal | y() const |
TheQTextLine class represents a line of text inside aQTextLayout.
A text line is usually created byQTextLayout::createLine().
After being created, the line can be filled using thesetLineWidth() orsetNumColumns() functions. A line has a number of attributes including the rectangle it occupies,rect(), its coordinates,x() andy(), itstextLength(),width() andnaturalTextWidth(), and itsascent() and decent() relative to the text. The position of the cursor in terms of the line is available fromcursorToX() and its inverse fromxToCursor(). A line can be moved withsetPosition().
| Constant | Value |
|---|---|
QTextLine::CursorBetweenCharacters | 0 |
QTextLine::CursorOnCharacter | 1 |
| Constant | Value |
|---|---|
QTextLine::Leading | 0 |
QTextLine::Trailing | 1 |
Creates an invalid line.
Returns the line's ascent.
See alsodescent() andheight().
Converts the cursor positioncursorPos to the corresponding x position inside the line, taking account of theedge.
IfcursorPos 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 alsoxToCursor().
This is an overloaded function.
Returns the line's descent.
Draws a line on the givenpainter at the specifiedposition. Theselection is reserved for internal use.
Returns the line's height. This is equal toascent() +descent() + 1 if leading is not included. If leading is included, this equals toascent() +descent() +leading() + 1.
See alsoascent(),descent(),leading(), andsetLeadingIncluded().
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.
This function was introduced in Qt 4.7.
Returns true if this text line is valid; otherwise returns false.
Returns the line's leading.
This function was introduced in Qt 4.6.
See alsoascent(),descent(), andheight().
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 alsosetLeadingIncluded().
Returns the position of the line in the text engine.
Returns the rectangle covered by the line.
Returns the width of the line that is occupied by text. This is always <= towidth(), and is the minimum width that could be used by layout() without changing the line break position.
Returns the line's position relative to the text layout's position.
See alsosetPosition().
Returns the line's bounding rectangle.
See alsox(),y(),textLength(), andwidth().
Includes positive leading into the line's height ifincluded 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 alsoleadingIncluded().
Lays out the line with the givenwidth. 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.
Lays out the line. The line is filled from its starting position with as many characters as are specified bynumColumns. In case the text cannot be split untilnumColumns characters, the line will be filled with as many characters to the next whitespace or end of the text.
Lays out the line. The line is filled from its starting position with as many characters as are specified bynumColumns. In case the text cannot be split untilnumColumns characters, the line will be filled with as many characters to the next whitespace or end of the text. The providedalignmentWidth is used as reference width for alignment.
Moves the line to positionpos.
See alsoposition().
Returns the length of the text in the line.
See alsonaturalTextWidth().
Returns the start of the line from the beginning of the string passed to theQTextLayout.
Returns the line's width as specified by the layout() function.
See alsonaturalTextWidth(),x(),y(),textLength(), andrect().
Returns the line's x position.
See alsorect(),y(),textLength(), andwidth().
Converts the x-coordinatex, to the nearest matching cursor position, depending on the cursor position type,cpos.
See alsocursorToX().
Returns the line's y position.
See alsox(),rect(),textLength(), andwidth().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.