PySide6.QtGui.QTextLine¶
- class QTextLine¶
QTextLine
类表示QTextLayout
中的一行文本。更多…概要¶
方法¶
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()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
一行文本通常由
createLine()
创建。创建后,可以使用
setLineWidth()
或setNumColumns()
函数填充该行。一行具有多个属性,包括它占据的矩形rect()
,它的坐标x()
和y()
,它的textLength()
,width()
和naturalTextWidth()
,以及它相对于文本的ascent()
和descent()
。光标在行中的位置可以从cursorToX()
获取,其逆操作可以从xToCursor()
获取。可以使用setPosition()
移动一行。- class Edge¶
常量
描述
QTextLine.Leading
QTextLine.Trailing
- class CursorPosition¶
常量
描述
QTextLine.CursorBetweenCharacters
QTextLine.CursorOnCharacter
- __init__()¶
创建一条无效的线。
- ascent()¶
- Return type:
浮点数
返回行的上升高度。
- cursorToX(cursorPos[, edge=QTextLine.Edge.Leading])¶
- Parameters:
cursorPos – int
edge –
Edge
- Return type:
PyObject
这是一个重载函数。
- descent()¶
- Return type:
浮点数
返回行的下降部分。
在给定的
painter
上绘制一条线,位置为指定的position
。这是一个重载函数。
返回此
QTextLine
中由from
和length
定义的字符范围内所有字形的索引和位置。from
索引相对于包含的QTextLayout
中的文本开头,并且范围必须在QTextLine
的范围内,如函数textStart()
和textLength()
所给出的。如果
from
为负数,它将默认为textStart()
,如果length
为负数,它将默认为textLength()
的返回值。注意
这相当于调用
glyphRuns
(from, length, QTextLayout::GlyphRunRetrievalFlag::GlyphIndexes | QTextLayout::GlyphRunRetrievalFlag::GlyphPositions)。另请参阅
- glyphRuns(from, length, flags)
- Parameters:
from – 整数
length – int
flags –
GlyphRunRetrievalFlag
的组合
- Return type:
QGlyphRun的列表
返回此
QTextLine
中由from
和length
定义的字符范围内所有字形的索引和位置。from
索引相对于包含的QTextLayout
中的文本开头,并且范围必须在QTextLine
的范围内,如函数textStart()
和textLength()
所给出的。retrievalFlags
指定了将从布局中检索QGlyphRun
的哪些属性。为了最小化分配和内存消耗,应将其设置为仅包含您稍后需要访问的属性。如果
from
为负数,它将默认为textStart()
,如果length
为负数,它将默认为textLength()
的返回值。另请参阅
- height()¶
- Return type:
浮点数
返回行的高度。如果不包括行间距,这等于
ascent()
+descent()
。如果包括行间距,这等于ascent()
+descent()
+leading()
。- horizontalAdvance()¶
- Return type:
浮点数
返回文本的水平前进距离。文本的前进距离是从其位置到下一个自然绘制文本的位置的距离。
通过将前进量添加到文本行的位置,并将其用作第二行文本的位置,您将能够将两行并排放置,中间没有间隙。
- isValid()¶
- Return type:
布尔
如果此文本行有效,则返回
true
;否则返回false
。- leading()¶
- Return type:
浮点数
返回行的前导。
- leadingIncluded()¶
- Return type:
布尔
如果正的行间距包含在行的高度中,则返回
true
;否则返回false
。默认情况下,不包含前导。
另请参阅
- lineNumber()¶
- Return type:
整数
返回文本引擎中行的位置。
返回该行覆盖的矩形。
- naturalTextWidth()¶
- Return type:
浮点数
返回文本占用的行宽。这总是小于或等于
width()
,并且是layout()在不改变换行位置的情况下可以使用的最小宽度。返回线条相对于文本布局位置的位置。
另请参阅
返回线条的边界矩形。
另请参阅
- setLeadingIncluded(included)¶
- Parameters:
包含 – 布尔值
如果
included
为真,则包括正前导到行的高度;否则不包括前导。默认情况下,不包含前导。
请注意,负的行距被忽略,必须通过让行重叠的方式在代码中使用文本行来处理。
另请参阅
- setLineWidth(width)¶
- Parameters:
width – 浮点数
使用给定的
width
布局行。从起始位置开始,行中填充尽可能多的字符。如果文本不能在行尾分割,则会填充额外的字符直到下一个空格或文本结束。- setNumColumns(columns)¶
- Parameters:
columns – int
布局该行。该行从其起始位置开始填充,填充的字符数量由
numColumns
指定。如果文本在numColumns
字符之前无法分割,则该行将填充尽可能多的字符,直到下一个空白或文本结束。- setNumColumns(columns, alignmentWidth)
- Parameters:
columns – 整数
alignmentWidth – 浮点数
布局该行。从起始位置开始,该行将填充由
numColumns
指定的尽可能多的字符。如果文本在numColumns
字符之前无法分割,则该行将填充尽可能多的字符直到下一个空白或文本结束。提供的alignmentWidth
用作对齐的参考宽度。将行移动到位置
pos
。另请参阅
- textLength()¶
- Return type:
整数
返回行中文本的长度。
另请参阅
- textStart()¶
- Return type:
整数
返回从传递给
QTextLayout
的字符串开头开始的行首。- width()¶
- Return type:
浮点数
返回由layout()函数指定的线条宽度。
- x()¶
- Return type:
浮点数
返回线条的x位置。
另请参阅
- xToCursor(x[, cpos=QTextLine.CursorPosition.CursorBetweenCharacters])¶
- Parameters:
x – 浮点数
cpos –
CursorPosition
- Return type:
整数
将x坐标
x
转换为最接近的匹配光标位置,具体取决于光标位置类型cpos
。请注意,结果光标位置可能包括预编辑区域文本。另请参阅
- y()¶
- Return type:
浮点数
返回线条的y位置。
另请参阅