继承者: QTextTableCellFormat , QTextImageFormat
PySide.QtGui.QTextCharFormat class provides formatting information for characters in a PySide.QtGui.QTextDocument .
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 PySide.QtGui.QTextCharFormat.setFont() function, and each aspect of its appearance can be adjusted to give the desired effect. PySide.QtGui.QTextCharFormat.setFontFamily() and PySide.QtGui.QTextCharFormat.setFontPointSize() define the font's family (e.g. Times) and printed size; PySide.QtGui.QTextCharFormat.setFontWeight() and PySide.QtGui.QTextCharFormat.setFontItalic() provide control over the style of the font. PySide.QtGui.QTextCharFormat.setFontUnderline() , PySide.QtGui.QTextCharFormat.setFontOverline() , PySide.QtGui.QTextCharFormat.setFontStrikeOut() ,和 PySide.QtGui.QTextCharFormat.setFontFixedPitch() provide additional effects for text.
The color is set with PySide.QtGui.QTextFormat.setForeground() . If the text is intended to be used as an anchor (for hyperlinks), this can be enabled with PySide.QtGui.QTextCharFormat.setAnchor() 。 PySide.QtGui.QTextCharFormat.setAnchorHref() and PySide.QtGui.QTextCharFormat.setAnchorNames() functions are used to specify the information about the hyperlink's destination and the anchor's name.
| 参数: |
|
|---|
Constructs a new character format object.
Creates a new character format with the same attributes as the given text format.
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. |
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 Qt.SolidLine . |
| QTextCharFormat.DashUnderline | Dashes are drawn using Qt.DashLine . |
| QTextCharFormat.DotLine | Dots are drawn using Qt.DotLine ; |
| QTextCharFormat.DashDotLine | Dashs and dots are drawn using Qt.DashDotLine . |
| QTextCharFormat.DashDotDotLine | Underlines draw drawn using Qt.DashDotDotLine . |
| QTextCharFormat.WaveUnderline | The text is underlined using a wave shaped line. |
| QTextCharFormat.SpellCheckUnderline | The underline is drawn depending on the QStyle::SH_SpellCeckUnderlineStyle style hint of the PySide.QtGui.QApplication style. By default this is mapped to WaveUnderline , on Mac OS X it is mapped to DashDotLine . |
另请参阅
Qt.PenStyle
| 返回类型: | unicode |
|---|
Returns the text format's hypertext link, or an empty string if none has been set.
| 返回类型: | 字符串列表 |
|---|
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.
| 返回类型: | PySide.QtGui.QFont |
|---|
Returns the font for this character format.
| 返回类型: | PySide.QtGui.QFont.Capitalization |
|---|
Returns the current capitalization type of the font.
| 返回类型: | unicode |
|---|
Returns the text format's font family.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the text format's font is fixed pitch; otherwise returns false.
| 返回类型: | PySide.QtGui.QFont.HintingPreference |
|---|
Returns the hinting preference set for this text format.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the text format's font is italic; otherwise returns false.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the font kerning is enabled.
| 返回类型: | PySide.QtCore.qreal |
|---|
Returns the current letter spacing percentage.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the text format's font is overlined; otherwise returns false.
| 返回类型: | PySide.QtCore.qreal |
|---|
Returns the font size used to display text in this format.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the text format's font is struck out (has a horizontal line drawn through it); otherwise returns false.
| 返回类型: | PySide.QtGui.QFont.StyleHint |
|---|
Returns the font style hint.
| 返回类型: | PySide.QtGui.QFont.StyleStrategy |
|---|
Returns the current font style strategy.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the text format's font is underlined; otherwise returns false.
| 返回类型: | PySide.QtCore.int |
|---|
Returns the text format's font weight.
| 返回类型: | PySide.QtCore.qreal |
|---|
Returns the current word spacing value.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the text is formatted as an anchor; otherwise returns false.
| 参数: | anchor – PySide.QtCore.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 PySide.QtGui.QTextCharFormat.setAnchorHref() , and optionally PySide.QtGui.QTextCharFormat.setAnchorNames() to create a hypertext link.
| 参数: | 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 PySide.QtGui.QTextCharFormat.setAnchorNames() .
To format the text as a hypertext link use PySide.QtGui.QTextCharFormat.setAnchor() .
| 参数: | names – list of strings |
|---|
Sets the text format's anchor names . For the anchor to work as a hyperlink, the destination must be set with PySide.QtGui.QTextCharFormat.setAnchorHref() and the anchor must be enabled with PySide.QtGui.QTextCharFormat.setAnchor() .
| 参数: | font – PySide.QtGui.QFont |
|---|
Sets the text format's font .
| 参数: | capitalization – PySide.QtGui.QFont.Capitalization |
|---|
| 参数: | family – unicode |
|---|
Sets the text format's font family .
| 参数: | fixedPitch – PySide.QtCore.bool |
|---|
若 fixedPitch is true, sets the text format's font to be fixed pitch; otherwise a non-fixed pitch font is used.
| 参数: | hintingPreference – PySide.QtGui.QFont.HintingPreference |
|---|
| 参数: | italic – PySide.QtCore.bool |
|---|
若 italic is true, sets the text format's font to be italic; otherwise the font will be non-italic.
| 参数: | enable – PySide.QtCore.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.
| 参数: | spacing – PySide.QtCore.qreal |
|---|
Sets the letter spacing of this format to the given spacing , in percent. A value of 100 indicates default spacing; a value of 200 doubles the amount of space a letter takes.
| 参数: | overline – PySide.QtCore.bool |
|---|
若 overline is true, sets the text format's font to be overlined; otherwise the font is displayed non-overlined.
| 参数: | size – PySide.QtCore.qreal |
|---|
Sets the text format's font size .
| 参数: | strikeOut – PySide.QtCore.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.
| 参数: |
|
|---|
| 参数: | strategy – PySide.QtGui.QFont.StyleStrategy |
|---|
| 参数: | underline – PySide.QtCore.bool |
|---|
若 underline is true, sets the text format's font to be underlined; otherwise it is displayed non-underlined.
| 参数: | weight – PySide.QtCore.int |
|---|
Sets the text format's font weight to weight .
| 参数: | spacing – PySide.QtCore.qreal |
|---|
Sets the word spacing of this format to the given spacing , in pixels.
| 参数: | tableCellColumnSpan – PySide.QtCore.int |
|---|
If this character format is applied to characters in a table cell, the cell will span tableCellColumnSpan columns.
| 参数: | tableCellRowSpan – PySide.QtCore.int |
|---|
If this character format is applied to characters in a table cell, the cell will span tableCellRowSpan rows.
| 参数: | pen – PySide.QtGui.QPen |
|---|
Sets the pen used to draw the outlines of characters to the given pen .
| 参数: | tip – unicode |
|---|
Sets the tool tip for a fragment of text to the given text .
| 参数: | color – PySide.QtGui.QColor |
|---|
Sets the underline color used for the characters with this format to the color 指定。
| 参数: | style – PySide.QtGui.QTextCharFormat.UnderlineStyle |
|---|
Sets the style of underlining the text to style .
| 参数: | alignment – PySide.QtGui.QTextCharFormat.VerticalAlignment |
|---|
Sets the vertical alignment used for the characters with this format to the alignment 指定。
| 返回类型: | PySide.QtCore.int |
|---|
If this character format is applied to characters in a table cell, this function returns the number of columns spanned by the text (this may be 1); otherwise it returns 1.
| 返回类型: | PySide.QtCore.int |
|---|
If this character format is applied to characters in a table cell, this function returns the number of rows spanned by the text (this may be 1); otherwise it returns 1.
| 返回类型: | PySide.QtGui.QPen |
|---|
Returns the pen used to draw the outlines of characters in this format.
| 返回类型: | unicode |
|---|
Returns the tool tip that is displayed for a fragment of text.
| 返回类型: | PySide.QtGui.QColor |
|---|
Returns the color used to underline the characters with this format.
| 返回类型: | PySide.QtGui.QTextCharFormat.UnderlineStyle |
|---|
Returns the style of underlining the text.
| 返回类型: | PySide.QtGui.QTextCharFormat.VerticalAlignment |
|---|
Returns the vertical alignment used for characters with this format.