内容表

上一话题

QTextBlockUserData

下一话题

QTextCursor

QTextCharFormat

QTextCharFormat class provides formatting information for characters in a QTextDocument . 更多

Inheritance diagram of PySide2.QtGui.QTextCharFormat

继承者: QTextImageFormat , QTextTableCellFormat

概要

函数

详细描述

The character format of text in a document specifies the visual properties of the text, as well as information about its role in a hypertext document.

The font used can be set by supplying a font to the setFont() function, and each aspect of its appearance can be adjusted to give the desired effect. setFontFamily() and setFontPointSize() define the font’s family (e.g. Times) and printed size; setFontWeight() and setFontItalic() provide control over the style of the font. setFontUnderline() , setFontOverline() , setFontStrikeOut() ,和 setFontFixedPitch() provide additional effects for text.

The color is set with setForeground() . If the text is intended to be used as an anchor (for hyperlinks), this can be enabled with setAnchor() setAnchorHref() and setAnchorNames() functions are used to specify the information about the hyperlink’s destination and the anchor’s name.

class QTextCharFormat

QTextCharFormat(QTextCharFormat)

QTextCharFormat(fmt)

param QTextCharFormat

QTextCharFormat

param fmt

QTextFormat

Constructs a new character format object.

PySide2.QtGui.QTextCharFormat. VerticalAlignment

This enum describes the ways that adjacent characters can be vertically aligned.

常量

描述

QTextCharFormat.AlignNormal

Adjacent characters are positioned in the standard way for text in the writing system in use.

QTextCharFormat.AlignSuperScript

Characters are placed above the base line for normal text.

QTextCharFormat.AlignSubScript

Characters are placed below the base line for normal text.

QTextCharFormat.AlignMiddle

The center of the object is vertically aligned with the base line. Currently, this is only implemented for inline objects.

QTextCharFormat.AlignBottom

The bottom edge of the object is vertically aligned with the base line.

QTextCharFormat.AlignTop

The top edge of the object is vertically aligned with the base line.

QTextCharFormat.AlignBaseline

The base lines of the characters are aligned.

PySide2.QtGui.QTextCharFormat. UnderlineStyle

This enum describes the different ways drawing underlined text.

常量

描述

QTextCharFormat.NoUnderline

Text is draw without any underlining decoration.

QTextCharFormat.SingleUnderline

A line is drawn using SolidLine .

QTextCharFormat.DashUnderline

Dashes are drawn using DashLine .

QTextCharFormat.DotLine

Dots are drawn using DotLine ;

QTextCharFormat.DashDotLine

Dashs and dots are drawn using DashDotLine .

QTextCharFormat.DashDotDotLine

Underlines draw drawn using DashDotDotLine .

QTextCharFormat.WaveUnderline

The text is underlined using a wave shaped line.

QTextCharFormat.SpellCheckUnderline

The underline is drawn depending on the SpellCheckUnderlineStyle theme hint of QPlatformTheme. By default this is mapped to , on macOS it is mapped to .

另请参阅

PenStyle

PySide2.QtGui.QTextCharFormat. FontPropertiesInheritanceBehavior

This enum specifies how the setFont() function should behave with respect to unset font properties.

常量

描述

QTextCharFormat.FontPropertiesSpecifiedOnly

If a property is not explicitly set, do not change the text format’s property value.

QTextCharFormat.FontPropertiesAll

If a property is not explicitly set, override the text format’s property with a default value.

另请参阅

setFont()

PySide2.QtGui.QTextCharFormat. anchorHref ( )
返回类型

unicode

Returns the text format’s hypertext link, or an empty string if none has been set.

另请参阅

setAnchorHref()

PySide2.QtGui.QTextCharFormat. anchorName ( )
返回类型

unicode

注意

此函数被弃用。

This function is deprecated. Use anchorNames() 代替。

Returns the anchor name associated with this text format, or an empty string if none has been set. If the anchor name is set, text with this format can be the destination of a hypertext link.

另请参阅

setAnchorName()

PySide2.QtGui.QTextCharFormat. anchorNames ( )
返回类型

字符串列表

Returns the anchor names associated with this text format, or an empty string list if none has been set. If the anchor names are set, text with this format can be the destination of a hypertext link.

另请参阅

setAnchorNames()

PySide2.QtGui.QTextCharFormat. font ( )
返回类型

QFont

Returns the font for this character format.

另请参阅

setFont()

PySide2.QtGui.QTextCharFormat. fontCapitalization ( )
返回类型

Capitalization

Returns the current capitalization type of the font.

PySide2.QtGui.QTextCharFormat. fontFamilies ( )
返回类型

object

Returns the text format’s font families.

PySide2.QtGui.QTextCharFormat. fontFamily ( )
返回类型

unicode

Returns the text format’s font family.

PySide2.QtGui.QTextCharFormat. fontFixedPitch ( )
返回类型

bool

返回 true if the text format’s font is fixed pitch; otherwise returns false .

PySide2.QtGui.QTextCharFormat. fontHintingPreference ( )
返回类型

HintingPreference

Returns the hinting preference set for this text format.

PySide2.QtGui.QTextCharFormat. fontItalic ( )
返回类型

bool

返回 true if the text format’s font is italic; otherwise returns false .

PySide2.QtGui.QTextCharFormat. fontKerning ( )
返回类型

bool

返回 true if the font kerning is enabled.

PySide2.QtGui.QTextCharFormat. fontLetterSpacing ( )
返回类型

qreal

Returns the current letter spacing.

PySide2.QtGui.QTextCharFormat. fontLetterSpacingType ( )
返回类型

SpacingType

Returns the letter spacing type of this format..

PySide2.QtGui.QTextCharFormat. fontOverline ( )
返回类型

bool

返回 true if the text format’s font is overlined; otherwise returns false .

PySide2.QtGui.QTextCharFormat. fontPointSize ( )
返回类型

qreal

Returns the font size used to display text in this format.

PySide2.QtGui.QTextCharFormat. fontStretch ( )
返回类型

int

Returns the current font stretching.

另请参阅

setFontStretch()

PySide2.QtGui.QTextCharFormat. fontStrikeOut ( )
返回类型

bool

返回 true if the text format’s font is struck out (has a horizontal line drawn through it); otherwise returns false .

PySide2.QtGui.QTextCharFormat. fontStyleHint ( )
返回类型

StyleHint

Returns the font style hint.

PySide2.QtGui.QTextCharFormat. fontStyleName ( )
返回类型

object

Returns the text format’s font style name.

PySide2.QtGui.QTextCharFormat. fontStyleStrategy ( )
返回类型

StyleStrategy

Returns the current font style strategy.

PySide2.QtGui.QTextCharFormat. fontUnderline ( )
返回类型

bool

返回 true if the text format’s font is underlined; otherwise returns false .

PySide2.QtGui.QTextCharFormat. fontWeight ( )
返回类型

int

Returns the text format’s font weight.

另请参阅

setFontWeight() font() Weight

PySide2.QtGui.QTextCharFormat. fontWordSpacing ( )
返回类型

qreal

Returns the current word spacing value.

PySide2.QtGui.QTextCharFormat. isAnchor ( )
返回类型

bool

返回 true if the text is formatted as an anchor; otherwise returns false .

PySide2.QtGui.QTextCharFormat. setAnchor ( anchor )
参数

anchor bool

anchor is true, text with this format represents an anchor, and is formatted in the appropriate way; otherwise the text is formatted normally. (Anchors are hyperlinks which are often shown underlined and in a different color from plain text.)

The way the text is rendered is independent of whether or not the format has a valid anchor defined. Use setAnchorHref() , and optionally setAnchorNames() to create a hypertext link.

另请参阅

isAnchor()

PySide2.QtGui.QTextCharFormat. setAnchorHref ( value )
参数

value – unicode

Sets the hypertext link for the text format to the given value . This is typically a URL like “ http://example.com/index.html ”.

The anchor will be displayed with the value as its display text; if you want to display different text call setAnchorNames() .

To format the text as a hypertext link use setAnchor() .

另请参阅

anchorHref()

PySide2.QtGui.QTextCharFormat. setAnchorName ( name )
参数

name – unicode

注意

此函数被弃用。

This function is deprecated. Use setAnchorNames() 代替。

Sets the text format’s anchor name . For the anchor to work as a hyperlink, the destination must be set with setAnchorHref() and the anchor must be enabled with setAnchor() .

另请参阅

anchorName()

PySide2.QtGui.QTextCharFormat. setAnchorNames ( names )
参数

names – 字符串列表

Sets the text format’s anchor names . For the anchor to work as a hyperlink, the destination must be set with setAnchorHref() and the anchor must be enabled with setAnchor() .

另请参阅

anchorNames()

PySide2.QtGui.QTextCharFormat. setFont ( font )
参数

font QFont

这是重载函数。

Sets the text format’s font .

另请参阅

font()

PySide2.QtGui.QTextCharFormat. setFont ( font , behavior )
参数

Sets the text format’s font .

behavior is FontPropertiesAll , the font property that has not been explicitly set is treated like as it were set with default value; If behavior is FontPropertiesSpecifiedOnly , the font property that has not been explicitly set is ignored and the respective property value remains unchanged.

另请参阅

font()

PySide2.QtGui.QTextCharFormat. setFontCapitalization ( capitalization )
参数

capitalization Capitalization

Sets the capitalization of the text that apppears in this font to capitalization .

A font’s capitalization makes the text appear in the selected capitalization mode.

PySide2.QtGui.QTextCharFormat. setFontFamilies ( families )
参数

families – 字符串列表

Sets the text format’s font families .

PySide2.QtGui.QTextCharFormat. setFontFamily ( family )
参数

family – unicode

Sets the text format’s font family .

PySide2.QtGui.QTextCharFormat. setFontFixedPitch ( fixedPitch )
参数

fixedPitch bool

fixedPitch is true, sets the text format’s font to be fixed pitch; otherwise a non-fixed pitch font is used.

PySide2.QtGui.QTextCharFormat. setFontHintingPreference ( hintingPreference )
参数

hintingPreference HintingPreference

Sets the hinting preference of the text format’s font to be hintingPreference .

PySide2.QtGui.QTextCharFormat. setFontItalic ( italic )
参数

italic bool

italic is true, sets the text format’s font to be italic; otherwise the font will be non-italic.

PySide2.QtGui.QTextCharFormat. setFontKerning ( enable )
参数

enable bool

Enables kerning for this font if enable is true; otherwise disables it.

When kerning is enabled, glyph metrics do not add up anymore, even for Latin text. In other words, the assumption that width(‘a’) + width(‘b’) is equal to width(“ab”) is not neccesairly true.

PySide2.QtGui.QTextCharFormat. setFontLetterSpacing ( spacing )
参数

spacing qreal

Sets the letter spacing of this format to the given spacing . The meaning of the value depends on the font letter spacing type.

For percentage spacing a value of 100 indicates default spacing; a value of 200 doubles the amount of space a letter takes.

PySide2.QtGui.QTextCharFormat. setFontLetterSpacingType ( letterSpacingType )
参数

letterSpacingType SpacingType

Sets the letter spacing type of this format to letterSpacingType .

PySide2.QtGui.QTextCharFormat. setFontOverline ( overline )
参数

overline bool

overline is true, sets the text format’s font to be overlined; otherwise the font is displayed non-overlined.

PySide2.QtGui.QTextCharFormat. setFontPointSize ( size )
参数

size qreal

Sets the text format’s font size .

PySide2.QtGui.QTextCharFormat. setFontStretch ( factor )
参数

factor int

Sets the stretch factor for the font to factor .

The stretch factor changes the width of all characters in the font by factor percent. For example, setting factor to 150 results in all characters in the font being 1.5 times (ie. 150%) wider. The default stretch factor is 100. The minimum stretch factor is 1, and the maximum stretch factor is 4000.

The stretch factor is only applied to outline fonts. The stretch factor is ignored for bitmap fonts.

另请参阅

fontStretch()

PySide2.QtGui.QTextCharFormat. setFontStrikeOut ( strikeOut )
参数

strikeOut bool

strikeOut is true, sets the text format’s font with strike-out enabled (with a horizontal line through it); otherwise it is displayed without strikeout.

PySide2.QtGui.QTextCharFormat. setFontStyleHint ( hint [ , strategy=QFont.PreferDefault ] )
参数
  • hint StyleHint

  • strategy StyleStrategy

Sets the font style hint and strategy .

Qt does not support style hints on X11 since this information is not provided by the window system.

PySide2.QtGui.QTextCharFormat. setFontStyleName ( styleName )
参数

styleName – unicode

Sets the text format’s font styleName .

PySide2.QtGui.QTextCharFormat. setFontStyleStrategy ( strategy )
参数

strategy StyleStrategy

Sets the font style strategy .

PySide2.QtGui.QTextCharFormat. setFontUnderline ( underline )
参数

underline bool

underline is true, sets the text format’s font to be underlined; otherwise it is displayed non-underlined.

PySide2.QtGui.QTextCharFormat. setFontWeight ( weight )
参数

weight int

Sets the text format’s font weight to weight .

另请参阅

fontWeight() setFont() Weight

PySide2.QtGui.QTextCharFormat. setFontWordSpacing ( spacing )
参数

spacing qreal

Sets the word spacing of this format to the given spacing , in pixels.

另请参阅

fontWordSpacing()

PySide2.QtGui.QTextCharFormat. setTableCellColumnSpan ( tableCellColumnSpan )
参数

tableCellColumnSpan int

PySide2.QtGui.QTextCharFormat. setTableCellRowSpan ( tableCellRowSpan )
参数

tableCellRowSpan int

PySide2.QtGui.QTextCharFormat. setTextOutline ( pen )
参数

pen QPen

Sets the pen used to draw the outlines of characters to the given pen .

另请参阅

textOutline()

PySide2.QtGui.QTextCharFormat. setToolTip ( tip )
参数

tip – unicode

Sets the tool tip for a fragment of text to the given text .

另请参阅

toolTip()

PySide2.QtGui.QTextCharFormat. setUnderlineColor ( color )
参数

color QColor

Sets the underline color used for the characters with this format to the color 指定。

另请参阅

underlineColor()

PySide2.QtGui.QTextCharFormat. setUnderlineStyle ( style )
参数

style UnderlineStyle

Sets the style of underlining the text to style .

另请参阅

underlineStyle()

PySide2.QtGui.QTextCharFormat. setVerticalAlignment ( alignment )
参数

alignment VerticalAlignment

Sets the vertical alignment used for the characters with this format to the alignment 指定。

PySide2.QtGui.QTextCharFormat. tableCellColumnSpan ( )
返回类型

int

PySide2.QtGui.QTextCharFormat. tableCellRowSpan ( )
返回类型

int

PySide2.QtGui.QTextCharFormat. textOutline ( )
返回类型

QPen

Returns the pen used to draw the outlines of characters in this format.

另请参阅

setTextOutline()

PySide2.QtGui.QTextCharFormat. toolTip ( )
返回类型

unicode

Returns the tool tip that is displayed for a fragment of text.

另请参阅

setToolTip()

PySide2.QtGui.QTextCharFormat. underlineColor ( )
返回类型

QColor

Returns the color used to underline the characters with this format.

PySide2.QtGui.QTextCharFormat. underlineStyle ( )
返回类型

UnderlineStyle

Returns the style of underlining the text.

PySide2.QtGui.QTextCharFormat. verticalAlignment ( )
返回类型

VerticalAlignment

Returns the vertical alignment used for characters with this format.