Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QTextLine Class

TheQTextLine class represents a line of text inside aQTextLayout.More...

Header:#include <QTextLine>

Note: All functions in this class arereentrant.

Public Types

enumCursorPosition { CursorBetweenCharacters, CursorOnCharacter }
enumEdge { Leading, Trailing }

Public Functions

QTextLine()
qrealascent() const
qrealcursorToX(int * cursorPos, Edge edge = Leading) const
qrealcursorToX(int cursorPos, Edge edge = Leading) const
qrealdescent() const
voiddraw(QPainter * painter, const QPointF & position, const QTextLayout::FormatRange * selection = 0) const
qrealheight() const
qrealhorizontalAdvance() const
boolisValid() const
qrealleading() const
boolleadingIncluded() const
intlineNumber() const
QRectFnaturalTextRect() const
qrealnaturalTextWidth() const
QPointFposition() const
QRectFrect() const
voidsetLeadingIncluded(bool included)
voidsetLineWidth(qreal width)
voidsetNumColumns(int numColumns)
voidsetNumColumns(int numColumns, qreal alignmentWidth)
voidsetPosition(const QPointF & pos)
inttextLength() const
inttextStart() const
qrealwidth() const
qrealx() const
intxToCursor(qreal x, CursorPosition cpos = CursorBetweenCharacters) const
qrealy() const

Detailed Description

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

Member Type Documentation

enum QTextLine::CursorPosition

ConstantValue
QTextLine::CursorBetweenCharacters0
QTextLine::CursorOnCharacter1

enum QTextLine::Edge

ConstantValue
QTextLine::Leading0
QTextLine::Trailing1

Member Function Documentation

QTextLine::QTextLine()

Creates an invalid line.

qreal QTextLine::ascent() const

Returns the line's ascent.

See alsodescent() andheight().

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

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

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

This is an overloaded function.

qreal QTextLine::descent() const

Returns the line's descent.

See alsoascent() andheight().

void QTextLine::draw(QPainter * painter, constQPointF & position, constQTextLayout::FormatRange * selection = 0) const

Draws a line on the givenpainter at the specifiedposition. Theselection is reserved for internal use.

qreal QTextLine::height() const

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

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.

This function was introduced in Qt 4.7.

bool QTextLine::isValid() const

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

qreal QTextLine::leading() const

Returns the line's leading.

This function was introduced in Qt 4.6.

See alsoascent(),descent(), andheight().

bool QTextLine::leadingIncluded() const

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

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 <= towidth(), 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.

See alsosetPosition().

QRectF QTextLine::rect() const

Returns the line's bounding rectangle.

See alsox(),y(),textLength(), andwidth().

void QTextLine::setLeadingIncluded(bool included)

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

void QTextLine::setLineWidth(qreal width)

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.

void QTextLine::setNumColumns(int numColumns)

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.

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

void QTextLine::setPosition(constQPointF & pos)

Moves the line to positionpos.

See alsoposition().

int QTextLine::textLength() const

Returns the length of the text in the line.

See alsonaturalTextWidth().

int QTextLine::textStart() const

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

qreal QTextLine::width() const

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

See alsonaturalTextWidth(),x(),y(),textLength(), andrect().

qreal QTextLine::x() const

Returns the line's x position.

See alsorect(),y(),textLength(), andwidth().

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

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

See alsocursorToX().

qreal QTextLine::y() const

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.


[8]ページ先頭

©2009-2025 Movatter.jp