PySide6.QtGui.QTextCharFormat¶
- class QTextCharFormat¶
QTextCharFormat
类为QTextDocument
中的字符提供格式化信息。更多…继承者:
QTextTableCellFormat
,QTextImageFormat
概要¶
方法¶
def
__init__()
def
anchorHref()
def
anchorNames()
def
baselineOffset()
def
font()
def
fontFamilies()
def
fontFamily()
def
fontFixedPitch()
def
fontItalic()
def
fontKerning()
def
fontOverline()
def
fontPointSize()
def
fontStretch()
def
fontStrikeOut()
def
fontStyleHint()
def
fontStyleName()
def
fontUnderline()
def
fontWeight()
def
isAnchor()
def
setAnchor()
def
setAnchorHref()
def
setAnchorNames()
def
setFont()
def
setFontFamily()
def
setFontItalic()
def
setFontKerning()
def
setFontStretch()
def
setFontWeight()
def
setTextOutline()
def
setToolTip()
def
textOutline()
def
toolTip()
def
underlineColor()
def
underlineStyle()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
文档中文本的字符格式指定了文本的视觉属性,以及它在超文本文档中的角色信息。
可以通过向
setFont()
函数提供字体来设置所使用的字体,并且可以调整其外观的每个方面以达到所需的效果。setFontFamilies()
和setFontPointSize()
定义了字体的家族(例如Times)和打印大小;setFontWeight()
和setFontItalic()
提供了对字体样式的控制。setFontUnderline()
、setFontOverline()
、setFontStrikeOut()
和setFontFixedPitch()
为文本提供了额外的效果。颜色是通过
setForeground()
设置的。如果文本打算用作锚点(用于超链接),可以通过setAnchor()
启用。setAnchorHref()
和setAnchorNames()
函数用于指定超链接目标和锚点名称的信息。- class VerticalAlignment¶
此枚举描述了相邻字符可以垂直对齐的方式。
常量
描述
QTextCharFormat.AlignNormal
相邻字符按照使用中的书写系统的标准方式定位。
QTextCharFormat.AlignSuperScript
字符被放置在正常文本的基线上方。
QTextCharFormat.AlignSubScript
字符被放置在正常文本的基线下方。
QTextCharFormat.AlignMiddle
对象的中心与基线垂直对齐。目前,这仅适用于内联对象。
QTextCharFormat.AlignBottom
对象的底边与基线垂直对齐。
QTextCharFormat.AlignTop
对象的顶部边缘与基线垂直对齐。
QTextCharFormat.AlignBaseline
字符的基线对齐。
- class UnderlineStyle¶
此枚举描述了绘制带下划线文本的不同方式。
常量
描述
QTextCharFormat.NoUnderline
文本绘制时没有任何下划线装饰。
QTextCharFormat.SingleUnderline
使用Qt::SolidLine绘制一条线。
QTextCharFormat.DashUnderline
使用Qt::DashLine绘制虚线。
QTextCharFormat.DotLine
使用Qt::DotLine绘制点线;
QTextCharFormat.DashDotLine
使用Qt::DashDotLine绘制虚线和点。
QTextCharFormat.DashDotDotLine
下划线使用Qt::DashDotDotLine绘制。
QTextCharFormat.WaveUnderline
文本使用波浪形线条下划线。
QTextCharFormat.SpellCheckUnderline
下划线的绘制取决于QPlatformTheme的SpellCheckUnderlineStyle主题提示。默认情况下,这映射为WaveUnderline,在macOS上映射为DotLine。
另请参阅
PenStyle
- class FontPropertiesInheritanceBehavior¶
此枚举指定了
setFont()
函数在未设置的字体属性方面应如何表现。常量
描述
QTextCharFormat.FontPropertiesSpecifiedOnly
如果未明确设置属性,则不要更改文本格式的属性值。
QTextCharFormat.FontPropertiesAll
如果未明确设置属性,则使用默认值覆盖文本格式的属性。
另请参阅
- __init__()¶
构造一个新的字符格式对象。
- __init__(fmt)
- Parameters:
fmt –
QTextFormat
- anchorHref()¶
- Return type:
字符串
返回文本格式的超文本链接,如果未设置则返回空字符串。
另请参阅
- anchorNames()¶
- Return type:
字符串列表
返回与此文本格式关联的锚点名称,如果未设置,则返回空字符串列表。如果设置了锚点名称,则具有此格式的文本可以成为超文本链接的目标。
另请参阅
- baselineOffset()¶
- Return type:
浮点数
返回基线偏移的百分比。
返回此字符格式的字体。
另请参阅
- fontCapitalization()¶
- Return type:
返回字体的当前大写类型。
- fontFamilies()¶
- Return type:
对象
返回文本格式的字体家族。
注意
由于历史原因,此函数返回一个QVariant。它将在Qt 7中修正为返回QStringList。该变体包含一个QStringList对象,可以通过调用
toStringList()
来提取它。另请参阅
- fontFamily()¶
- Return type:
字符串
注意
此函数已弃用。
请使用
fontFamilies()
代替。返回文本格式的字体家族。
另请参阅
- fontFixedPitch()¶
- Return type:
布尔
如果文本格式的字体是等宽的,则返回
true
;否则返回false
。- fontHintingPreference()¶
- Return type:
返回为此文本格式设置的提示偏好。
- fontItalic()¶
- Return type:
布尔
如果文本格式的字体是斜体,则返回
true
;否则返回false
。另请参阅
- fontKerning()¶
- Return type:
布尔
如果启用了字体字距调整,则返回
true
。另请参阅
- fontLetterSpacing()¶
- Return type:
浮点数
返回当前的字母间距。
- fontLetterSpacingType()¶
- Return type:
返回此格式的字母间距类型。
- fontOverline()¶
- Return type:
布尔
如果文本格式的字体有上划线,则返回
true
;否则返回false
。另请参阅
- fontPointSize()¶
- Return type:
浮点数
返回用于以这种格式显示文本的字体大小。
另请参阅
- fontStretch()¶
- Return type:
整数
返回当前的字体拉伸。
另请参阅
- fontStrikeOut()¶
- Return type:
布尔
如果文本格式的字体被划掉(有一条水平线穿过),则返回
true
;否则返回false
。另请参阅
返回字体样式提示。
另请参阅
- fontStyleName()¶
- Return type:
对象
返回文本格式的字体样式名称。
注意
由于历史原因,此函数返回一个QVariant。它将在Qt 7中修正为返回QStringList。该变体包含一个QStringList对象,可以通过调用
toStringList()
来提取它。- fontStyleStrategy()¶
- Return type:
返回当前的字体样式策略。
- fontUnderline()¶
- Return type:
布尔
如果文本格式的字体带有下划线,则返回
true
;否则返回false
。另请参阅
- fontWeight()¶
- Return type:
整数
返回文本格式的字体粗细。
另请参阅
- fontWordSpacing()¶
- Return type:
浮点数
返回当前的字间距值。
另请参阅
- isAnchor()¶
- Return type:
布尔
如果文本格式化为锚点,则返回
true
;否则返回false
。- setAnchor(anchor)¶
- Parameters:
anchor – 布尔值
如果
anchor
为 true,则具有此格式的文本表示一个锚点,并以适当的方式格式化;否则文本正常格式化。(锚点是超链接,通常以下划线和与普通文本不同的颜色显示。)文本的渲染方式与格式是否定义了有效的锚点无关。使用
setAnchorHref()
,以及可选的setAnchorNames()
来创建超文本链接。另请参阅
- setAnchorHref(value)¶
- Parameters:
值 – str
将文本格式的超文本链接设置为给定的
value
。这通常是一个URL,例如“http://example.com/index.html”。锚点将显示为
value
作为其显示文本;如果您想显示不同的文本,请调用setAnchorNames()
。要将文本格式化为超文本链接,请使用
setAnchor()
。另请参阅
- setAnchorNames(names)¶
- Parameters:
names – 字符串列表
设置文本格式的锚点
names
。要使锚点作为超链接工作,必须使用setAnchorHref()
设置目标,并且必须使用setAnchor()
启用锚点。另请参阅
- setBaselineOffset(baseline)¶
- Parameters:
baseline – 浮点数
设置文本的基线(以高度的百分比表示)为
baseline
。正值将文本向上移动相应的百分比;负值将其向下移动。默认值为0。- setFont(font[, behavior=QTextCharFormat.FontPropertiesInheritanceBehavior.FontPropertiesAll])¶
- Parameters:
字体 –
QFont
设置文本格式的
font
。如果
behavior
是FontPropertiesAll
,未明确设置的字体属性将被视为已使用默认值设置;如果behavior
是FontPropertiesSpecifiedOnly
,未明确设置的字体属性将被忽略,并且相应的属性值保持不变。另请参阅
- setFontCapitalization(capitalization)¶
- Parameters:
大写 –
Capitalization
设置此字体中出现的文本的大小写为
capitalization
。字体的首字母大写功能使文本以选定的首字母大写模式显示。
另请参阅
- setFontFamilies(families)¶
- Parameters:
families – 字符串列表
设置文本格式的字体
families
。另请参阅
- setFontFamily(family)¶
- Parameters:
family – str
注意
此函数已弃用。
请使用
setFontFamilies()
代替。设置文本格式的字体
family
。另请参阅
- setFontFixedPitch(fixedPitch)¶
- Parameters:
fixedPitch – 布尔值
如果
fixedPitch
为 true,则将文本格式的字体设置为固定间距;否则使用非固定间距字体。- setFontHintingPreference(hintingPreference)¶
- Parameters:
hintingPreference –
HintingPreference
将文本格式字体的提示偏好设置为
hintingPreference
。- setFontItalic(italic)¶
- Parameters:
斜体 – bool
如果
italic
为真,则将文本格式的字体设置为斜体;否则字体将不为斜体。另请参阅
- setFontKerning(enable)¶
- Parameters:
enable – 布尔值
如果
enable
为true,则启用此字体的字距调整;否则禁用它。当启用字距调整时,即使对于拉丁文本,字形度量也不再相加。换句话说,假设 width('a') + width('b') 等于 width("ab") 并不一定成立。
另请参阅
- setFontLetterSpacing(spacing)¶
- Parameters:
间距 – float
将此格式的字母间距设置为给定的
spacing
。值的含义取决于字体字母间距类型。对于百分比间距,值为100表示默认间距;值为200表示字母占用的空间量加倍。
- setFontLetterSpacingType(letterSpacingType)¶
- Parameters:
letterSpacingType –
SpacingType
将此格式的字母间距类型设置为
letterSpacingType
。- setFontOverline(overline)¶
- Parameters:
上划线 – 布尔值
如果
overline
为 true,则将文本格式的字体设置为上划线;否则字体显示为非上划线。另请参阅
- setFontPointSize(size)¶
- Parameters:
size – 浮点数
设置文本格式的字体
size
。另请参阅
- setFontStretch(factor)¶
- Parameters:
factor – int
将字体的拉伸因子设置为
factor
。拉伸因子按百分比改变字体中所有字符的宽度。例如,将
factor
设置为150会使字体中的所有字符宽度变为1.5倍(即150%)。默认的拉伸因子是100。最小拉伸因子是1,最大拉伸因子是4000。拉伸因子仅适用于轮廓字体。对于位图字体,拉伸因子将被忽略。
另请参阅
- setFontStrikeOut(strikeOut)¶
- Parameters:
strikeOut – 布尔值
如果
strikeOut
为 true,则设置文本格式的字体为启用删除线(带有一条水平线穿过);否则显示时不带删除线。另请参阅
- setFontStyleHint(hint[, strategy=QFont.PreferDefault])¶
- Parameters:
提示 –
StyleHint
strategy –
StyleStrategy
设置字体样式
hint
和strategy
。Qt 不支持在 X11 上的样式提示,因为窗口系统未提供此信息。
- setFontStyleName(styleName)¶
- Parameters:
styleName – str
设置文本格式的字体
styleName
。- setFontStyleStrategy(strategy)¶
- Parameters:
策略 –
StyleStrategy
设置字体样式
strategy
。- setFontUnderline(underline)¶
- Parameters:
下划线 – bool
如果
underline
为 true,则将文本格式的字体设置为下划线;否则显示为无下划线。另请参阅
- setFontWeight(weight)¶
- Parameters:
weight – int
将文本格式的字体粗细设置为
weight
。另请参阅
- setFontWordSpacing(spacing)¶
- Parameters:
间距 – float
将此格式的字间距设置为给定的
spacing
,单位为像素。另请参阅
- setSubScriptBaseline(baseline)¶
- Parameters:
baseline – 浮点数
将下标基线设置为字体高度的百分比为
baseline
。默认值为16.67%(高度的1/6)- setSuperScriptBaseline(baseline)¶
- Parameters:
baseline – 浮点数
将上标基线设置为字体高度的百分比到
baseline
。默认值为50%(高度的1/2)。- setTableCellColumnSpan(tableCellColumnSpan)¶
- Parameters:
tableCellColumnSpan – int
- setTableCellRowSpan(tableCellRowSpan)¶
- Parameters:
tableCellRowSpan – int
设置用于绘制字符轮廓的笔为给定的
pen
。另请参阅
- setToolTip(tip)¶
- Parameters:
提示 – str
将文本片段的工具提示设置为给定的
text
。另请参阅
将此格式用于绘制字符的下划线、上划线和删除线的颜色设置为指定的
color
。另请参阅
- setUnderlineStyle(style)¶
- Parameters:
样式 –
UnderlineStyle
设置文本下划线的样式为
style
。另请参阅
- setVerticalAlignment(alignment)¶
- Parameters:
对齐方式 –
VerticalAlignment
将此格式的字符的垂直对齐方式设置为指定的
alignment
。另请参阅
- subScriptBaseline()¶
- Return type:
浮点数
返回下标基线作为字体高度的百分比。
- superScriptBaseline()¶
- Return type:
浮点数
返回上标基线作为字体高度的百分比。
- tableCellColumnSpan()¶
- Return type:
整数
- tableCellRowSpan()¶
- Return type:
整数
返回用于绘制此格式中字符轮廓的笔。
另请参阅
- toolTip()¶
- Return type:
字符串
返回为文本片段显示的工具提示。
另请参阅
返回用于在此格式的字符上绘制下划线、上划线和删除线的颜色。
另请参阅
- underlineStyle()¶
- Return type:
返回文本的下划线样式。
另请参阅
- verticalAlignment()¶
- Return type:
返回用于此格式字符的垂直对齐方式。