Inherited by: QTextTableCellFormat, QTextImageFormat
The 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() , and 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() . The 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.
Parameters: |
|
---|
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.
Constant | Description |
---|---|
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 baseline for normal text. |
QTextCharFormat.AlignSubScript | Characters are placed below the baseline 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. |
This enum describes the different ways drawing underlined text.
Constant | Description |
---|---|
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 . |
See also
Qt.PenStyle
Return type: | unicode |
---|
Returns the text format’s hypertext link, or an empty string if none has been set.
Return type: | list of strings |
---|
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.
Return type: | PySide.QtGui.QFont |
---|
Returns the font for this character format.
Return type: | PySide.QtGui.QFont.Capitalization |
---|
Returns the current capitalization type of the font.
Return type: | unicode |
---|
Returns the text format’s font family.
Return type: | PySide.QtCore.bool |
---|
Returns true if the text format’s font is fixed pitch; otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
Returns true if the text format’s font is italic; otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
Returns true if the font kerning is enabled.
Return type: | PySide.QtCore.qreal |
---|
Returns the current letter spacing percentage.
Return type: | PySide.QtCore.bool |
---|
Returns true if the text format’s font is overlined; otherwise returns false.
Return type: | PySide.QtCore.qreal |
---|
Returns the font size used to display text in this format.
Return type: | PySide.QtCore.bool |
---|
Returns true if the text format’s font is struck out (has a horizontal line drawn through it); otherwise returns false.
Return type: | PySide.QtGui.QFont.StyleHint |
---|
Returns the font style hint.
Return type: | PySide.QtGui.QFont.StyleStrategy |
---|
Returns the current font style strategy.
Return type: | PySide.QtCore.bool |
---|
Returns true if the text format’s font is underlined; otherwise returns false.
Return type: | PySide.QtCore.int |
---|
Returns the text format’s font weight.
See also
PySide.QtGui.QTextCharFormat.setFontWeight() PySide.QtGui.QTextCharFormat.font() QFont.Weight
Return type: | PySide.QtCore.qreal |
---|
Returns the current word spacing value.
Return type: | PySide.QtCore.bool |
---|
Returns true if the text is formatted as an anchor; otherwise returns false.
Parameters: | anchor – PySide.QtCore.bool |
---|
If 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.
Parameters: | 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() .
Parameters: | 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() .
Parameters: | font – PySide.QtGui.QFont |
---|
Sets the text format’s font .
See also
Parameters: | capitalization – PySide.QtGui.QFont.Capitalization |
---|
Parameters: | family – unicode |
---|
Sets the text format’s font family .
Parameters: | fixedPitch – PySide.QtCore.bool |
---|
If fixedPitch is true, sets the text format’s font to be fixed pitch; otherwise a non-fixed pitch font is used.
Parameters: | italic – PySide.QtCore.bool |
---|
If italic is true, sets the text format’s font to be italic; otherwise the font will be non-italic.
Parameters: | 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.
Parameters: | 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.
Parameters: | overline – PySide.QtCore.bool |
---|
If overline is true, sets the text format’s font to be overlined; otherwise the font is displayed non-overlined.
Parameters: | size – PySide.QtCore.qreal |
---|
Sets the text format’s font size .
Parameters: | strikeOut – PySide.QtCore.bool |
---|
If 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.
Parameters: |
|
---|
Parameters: | strategy – PySide.QtGui.QFont.StyleStrategy |
---|
Parameters: | underline – PySide.QtCore.bool |
---|
If underline is true, sets the text format’s font to be underlined; otherwise it is displayed non-underlined.
Parameters: | weight – PySide.QtCore.int |
---|
Sets the text format’s font weight to weight .
See also
PySide.QtGui.QTextCharFormat.fontWeight() PySide.QtGui.QTextCharFormat.setFont() QFont.Weight
Parameters: | spacing – PySide.QtCore.qreal |
---|
Sets the word spacing of this format to the given spacing , in pixels.
Parameters: | tableCellColumnSpan – PySide.QtCore.int |
---|
If this character format is applied to characters in a table cell, the cell will span tableCellColumnSpan columns.
Parameters: | tableCellRowSpan – PySide.QtCore.int |
---|
If this character format is applied to characters in a table cell, the cell will span tableCellRowSpan rows.
Parameters: | pen – PySide.QtGui.QPen |
---|
Sets the pen used to draw the outlines of characters to the given pen .
Parameters: | tip – unicode |
---|
Sets the tool tip for a fragment of text to the given text .
Parameters: | color – PySide.QtGui.QColor |
---|
Sets the underline color used for the characters with this format to the color specified.
Parameters: | style – PySide.QtGui.QTextCharFormat.UnderlineStyle |
---|
Sets the style of underlining the text to style .
Parameters: | alignment – PySide.QtGui.QTextCharFormat.VerticalAlignment |
---|
Sets the vertical alignment used for the characters with this format to the alignment specified.
Return type: | 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.
Return type: | 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.
Return type: | PySide.QtGui.QPen |
---|
Returns the pen used to draw the outlines of characters in this format.
Return type: | unicode |
---|
Returns the tool tip that is displayed for a fragment of text.
Return type: | PySide.QtGui.QColor |
---|
Returns the color used to underline the characters with this format.
Return type: | PySide.QtGui.QTextCharFormat.UnderlineStyle |
---|
Returns the style of underlining the text.
Return type: | PySide.QtGui.QTextCharFormat.VerticalAlignment |
---|
Returns the vertical alignment used for characters with this format.