Table Of Contents

Previous topic

QFont

Next topic

QTextTableCellFormat

QTextCharFormat

Inherited by: QTextTableCellFormat, QTextImageFormat

Synopsis

Functions

Detailed Description

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.

class PySide.QtGui.QTextCharFormat
class PySide.QtGui.QTextCharFormat(QTextCharFormat)
class PySide.QtGui.QTextCharFormat(fmt)
Parameters:

Constructs a new character format object.

Creates a new character format with the same attributes as the given text format.

PySide.QtGui.QTextCharFormat.VerticalAlignment

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 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.
PySide.QtGui.QTextCharFormat.UnderlineStyle

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

PySide.QtGui.QTextCharFormat.anchorHref()
Return type:unicode

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

PySide.QtGui.QTextCharFormat.anchorNames()
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.

PySide.QtGui.QTextCharFormat.font()
Return type:PySide.QtGui.QFont

Returns the font for this character format.

PySide.QtGui.QTextCharFormat.fontCapitalization()
Return type:PySide.QtGui.QFont.Capitalization

Returns the current capitalization type of the font.

PySide.QtGui.QTextCharFormat.fontFamily()
Return type:unicode

Returns the text format’s font family.

PySide.QtGui.QTextCharFormat.fontFixedPitch()
Return type:PySide.QtCore.bool

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

PySide.QtGui.QTextCharFormat.fontHintingPreference()
Return type:PySide.QtGui.QFont.HintingPreference

Returns the hinting preference set for this text format.

PySide.QtGui.QTextCharFormat.fontItalic()
Return type:PySide.QtCore.bool

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

PySide.QtGui.QTextCharFormat.fontKerning()
Return type:PySide.QtCore.bool

Returns true if the font kerning is enabled.

PySide.QtGui.QTextCharFormat.fontLetterSpacing()
Return type:PySide.QtCore.qreal

Returns the current letter spacing percentage.

PySide.QtGui.QTextCharFormat.fontOverline()
Return type:PySide.QtCore.bool

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

PySide.QtGui.QTextCharFormat.fontPointSize()
Return type:PySide.QtCore.qreal

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

PySide.QtGui.QTextCharFormat.fontStrikeOut()
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.

PySide.QtGui.QTextCharFormat.fontStyleHint()
Return type:PySide.QtGui.QFont.StyleHint

Returns the font style hint.

PySide.QtGui.QTextCharFormat.fontStyleStrategy()
Return type:PySide.QtGui.QFont.StyleStrategy

Returns the current font style strategy.

PySide.QtGui.QTextCharFormat.fontUnderline()
Return type:PySide.QtCore.bool

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

PySide.QtGui.QTextCharFormat.fontWeight()
Return type:PySide.QtCore.int

Returns the text format’s font weight.

PySide.QtGui.QTextCharFormat.fontWordSpacing()
Return type:PySide.QtCore.qreal

Returns the current word spacing value.

PySide.QtGui.QTextCharFormat.isAnchor()
Return type:PySide.QtCore.bool

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

PySide.QtGui.QTextCharFormat.setAnchor(anchor)
Parameters:anchorPySide.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.

PySide.QtGui.QTextCharFormat.setAnchorHref(value)
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() .

PySide.QtGui.QTextCharFormat.setAnchorNames(names)
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() .

PySide.QtGui.QTextCharFormat.setFont(font)
Parameters:fontPySide.QtGui.QFont

Sets the text format’s font .

PySide.QtGui.QTextCharFormat.setFontCapitalization(capitalization)
Parameters:capitalizationPySide.QtGui.QFont.Capitalization
PySide.QtGui.QTextCharFormat.setFontFamily(family)
Parameters:family – unicode

Sets the text format’s font family .

PySide.QtGui.QTextCharFormat.setFontFixedPitch(fixedPitch)
Parameters:fixedPitchPySide.QtCore.bool

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

PySide.QtGui.QTextCharFormat.setFontHintingPreference(hintingPreference)
Parameters:hintingPreferencePySide.QtGui.QFont.HintingPreference
PySide.QtGui.QTextCharFormat.setFontItalic(italic)
Parameters:italicPySide.QtCore.bool

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

PySide.QtGui.QTextCharFormat.setFontKerning(enable)
Parameters:enablePySide.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.

PySide.QtGui.QTextCharFormat.setFontLetterSpacing(spacing)
Parameters:spacingPySide.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.

PySide.QtGui.QTextCharFormat.setFontOverline(overline)
Parameters:overlinePySide.QtCore.bool

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

PySide.QtGui.QTextCharFormat.setFontPointSize(size)
Parameters:sizePySide.QtCore.qreal

Sets the text format’s font size .

PySide.QtGui.QTextCharFormat.setFontStrikeOut(strikeOut)
Parameters:strikeOutPySide.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.

PySide.QtGui.QTextCharFormat.setFontStyleHint(hint[, strategy=QFont.PreferDefault])
Parameters:
PySide.QtGui.QTextCharFormat.setFontStyleStrategy(strategy)
Parameters:strategyPySide.QtGui.QFont.StyleStrategy
PySide.QtGui.QTextCharFormat.setFontUnderline(underline)
Parameters:underlinePySide.QtCore.bool

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

PySide.QtGui.QTextCharFormat.setFontWeight(weight)
Parameters:weightPySide.QtCore.int

Sets the text format’s font weight to weight .

PySide.QtGui.QTextCharFormat.setFontWordSpacing(spacing)
Parameters:spacingPySide.QtCore.qreal

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

PySide.QtGui.QTextCharFormat.setTableCellColumnSpan(tableCellColumnSpan)
Parameters:tableCellColumnSpanPySide.QtCore.int

If this character format is applied to characters in a table cell, the cell will span tableCellColumnSpan columns.

PySide.QtGui.QTextCharFormat.setTableCellRowSpan(tableCellRowSpan)
Parameters:tableCellRowSpanPySide.QtCore.int

If this character format is applied to characters in a table cell, the cell will span tableCellRowSpan rows.

PySide.QtGui.QTextCharFormat.setTextOutline(pen)
Parameters:penPySide.QtGui.QPen

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

PySide.QtGui.QTextCharFormat.setToolTip(tip)
Parameters:tip – unicode

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

PySide.QtGui.QTextCharFormat.setUnderlineColor(color)
Parameters:colorPySide.QtGui.QColor

Sets the underline color used for the characters with this format to the color specified.

PySide.QtGui.QTextCharFormat.setUnderlineStyle(style)
Parameters:stylePySide.QtGui.QTextCharFormat.UnderlineStyle

Sets the style of underlining the text to style .

PySide.QtGui.QTextCharFormat.setVerticalAlignment(alignment)
Parameters:alignmentPySide.QtGui.QTextCharFormat.VerticalAlignment

Sets the vertical alignment used for the characters with this format to the alignment specified.

PySide.QtGui.QTextCharFormat.tableCellColumnSpan()
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.

PySide.QtGui.QTextCharFormat.tableCellRowSpan()
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.

PySide.QtGui.QTextCharFormat.textOutline()
Return type:PySide.QtGui.QPen

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

PySide.QtGui.QTextCharFormat.toolTip()
Return type:unicode

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

PySide.QtGui.QTextCharFormat.underlineColor()
Return type:PySide.QtGui.QColor

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

PySide.QtGui.QTextCharFormat.underlineStyle()
Return type:PySide.QtGui.QTextCharFormat.UnderlineStyle

Returns the style of underlining the text.

PySide.QtGui.QTextCharFormat.verticalAlignment()
Return type:PySide.QtGui.QTextCharFormat.VerticalAlignment

Returns the vertical alignment used for characters with this format.