- class QTextLine#
The
QTextLine
class represents a line of text inside aQTextLayout
. More…Synopsis#
Methods#
def
__init__()
def
ascent()
def
cursorToX()
def
descent()
def
draw()
def
glyphRuns()
def
height()
def
isValid()
def
leading()
def
lineNumber()
def
position()
def
rect()
def
setLineWidth()
def
setNumColumns()
def
setPosition()
def
textLength()
def
textStart()
def
width()
def
x()
def
xToCursor()
def
y()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
A text line is usually created by
createLine()
.After being created, the line can be filled using the
setLineWidth()
orsetNumColumns()
functions. A line has a number of attributes including the rectangle it occupies,rect()
, its coordinates,x()
andy()
, itstextLength()
,width()
andnaturalTextWidth()
, and itsascent()
anddescent()
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()
.- class Edge#
Constant
Description
QTextLine.Leading
QTextLine.Trailing
- class CursorPosition#
Constant
Description
QTextLine.CursorBetweenCharacters
QTextLine.CursorOnCharacter
- __init__()#
Creates an invalid line.
- ascent()#
- Return type:
float
Returns the line’s ascent.
- cursorToX(cursorPos[, edge=QTextLine.Edge.Leading])#
- Parameters:
cursorPos – int
edge –
Edge
- Return type:
PyObject
This is an overloaded function.
- descent()#
- Return type:
float
Returns the line’s descent.
Draws a line on the given
painter
at the specifiedposition
.- glyphRuns([from=-1[, length=-1]])#
- Parameters:
from – int
length – int
- Return type:
.list of QGlyphRun
This is an overloaded function.
Returns the glyph indexes and positions for all glyphs in this
QTextLine
for characters in the range defined byfrom
andlength
. Thefrom
index is relative to the beginning of the text in the containingQTextLayout
, and the range must be within the range ofQTextLine
as given by functionstextStart()
andtextLength()
.If
from
is negative, it will default totextStart()
, and iflength
is negative it will default to the return value oftextLength()
.Note
This is equivalent to calling
glyphRuns
(from, length, QTextLayout::GlyphRunRetrievalFlag::GlyphIndexes | QTextLayout::GlyphRunRetrievalFlag::GlyphPositions).See also
- glyphRuns(from, length, flags)
- Parameters:
from – int
length – int
flags – Combination of
GlyphRunRetrievalFlag
- Return type:
.list of QGlyphRun
Returns the glyph indexes and positions for all glyphs in this
QTextLine
for characters in the range defined byfrom
andlength
. Thefrom
index is relative to the beginning of the text in the containingQTextLayout
, and the range must be within the range ofQTextLine
as given by functionstextStart()
andtextLength()
.The
retrievalFlags
specifies which properties of theQGlyphRun
will be retrieved from the layout. To minimize allocations and memory consumption, this should be set to include only the properties that you need to access later.If
from
is negative, it will default totextStart()
, and iflength
is negative it will default to the return value oftextLength()
.See also
- height()#
- Return type:
float
Returns the line’s height. This is equal to
ascent()
+descent()
if leading is not included. If leading is included, this equals toascent()
+descent()
+leading()
.See also
- horizontalAdvance()#
- Return type:
float
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.
- isValid()#
- Return type:
bool
Returns
true
if this text line is valid; otherwise returnsfalse
.- leading()#
- Return type:
float
Returns the line’s leading.
- leadingIncluded()#
- Return type:
bool
Returns
true
if positive leading is included into the line’s height; otherwise returnsfalse
.By default, leading is not included.
See also
- lineNumber()#
- Return type:
int
Returns the position of the line in the text engine.
Returns the rectangle covered by the line.
- naturalTextWidth()#
- Return type:
float
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.Returns the line’s position relative to the text layout’s position.
See also
Returns the line’s bounding rectangle.
See also
- setLeadingIncluded(included)#
- Parameters:
included – 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.
See also
- setLineWidth(width)#
- Parameters:
width – 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.- setNumColumns(columns)#
- Parameters:
columns – 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 untilnumColumns
characters, the line will be filled with as many characters to the next whitespace or end of the text.- setNumColumns(columns, alignmentWidth)
- Parameters:
columns – int
alignmentWidth – 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 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 position
pos
.See also
- textLength()#
- Return type:
int
Returns the length of the text in the line.
See also
- textStart()#
- Return type:
int
Returns the start of the line from the beginning of the string passed to the
QTextLayout
.- width()#
- Return type:
float
Returns the line’s width as specified by the layout() function.
See also
- x()#
- Return type:
float
Returns the line’s x position.
See also
- xToCursor(x[, edge=QTextLine.CursorPosition.CursorBetweenCharacters])#
- Parameters:
x – float
edge –
CursorPosition
- Return type:
int
Converts the x-coordinate
x
, to the nearest matching cursor position, depending on the cursor position type,cpos
. Note that result cursor position includes possible preedit area text.See also
- y()#
- Return type:
float
Returns the line’s y position.
See also