QTextCharFormat Class Reference

The QTextCharFormat class provides formatting information for characters in a QTextDocument.

  1. #include <QTextCharFormat>

Inherits: QTextFormat.

Inherited by: QTextImageFormat and QTextTableCellFormat.

Note: All functions in this class are reentrant.

Detailed Description

The QTextCharFormat class provides formatting information for characters in a 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 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(), and 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(). The setAnchorHref() and setAnchorNames() functions are used to specify the information about the hyperlink's destination and the anchor's name.

See also QTextFormat, QTextBlockFormat, QTextTableFormat, and QTextListFormat.

Public Types

Toggle detailsenum QTextCharFormat::

UnderlineStyleUnderlineStyle { NoUnderline , SingleUnderline , DashUnderline , DotLine , DashDotLine , DashDotDotLine , WaveUnderline , SpellCheckUnderline 7 ...} { NoUnderline , SingleUnderline , DashUnderline , DotLine , DashDotLine , DashDotDotLine , WaveUnderline , SpellCheckUnderline 7 }

This enum describes the different ways drawing underlined text.

ConstantValueDescription
QTextCharFormat::NoUnderline 0 Text is draw without any underlining decoration.
QTextCharFormat::SingleUnderline 1 A line is drawn using Qt::SolidLine.
QTextCharFormat::DashUnderline 2 Dashes are drawn using Qt::DashLine.
QTextCharFormat::DotLine 3 Dots are drawn using Qt::DotLine;
QTextCharFormat::DashDotLine 4 Dashs and dots are drawn using Qt::DashDotLine.
QTextCharFormat::DashDotDotLine 5 Underlines draw drawn using Qt::DashDotDotLine.
QTextCharFormat::WaveUnderline 6 The text is underlined using a wave shaped line.
QTextCharFormat::SpellCheckUnderline 7 The underline is drawn depending on the QStyle::SH_SpellCeckUnderlineStyle style hint of the QApplication style. By default this is mapped to WaveUnderline, on Mac OS X it is mapped to DashDotLine.

See also Qt::PenStyle.

Look up this member in the source code.

Toggle detailsenum QTextCharFormat::

VerticalAlignmentVerticalAlignment { AlignNormal , AlignSuperScript , AlignSubScript , AlignMiddle , AlignTop , AlignBottom 5 ...} { AlignNormal , AlignSuperScript , AlignSubScript , AlignMiddle , AlignTop , AlignBottom 5 }

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

ConstantValueDescription
QTextCharFormat::AlignNormal 0 Adjacent characters are positioned in the standard way for text in the writing system in use.
QTextCharFormat::AlignSuperScript 1 Characters are placed above the baseline for normal text.
QTextCharFormat::AlignSubScript 2 Characters are placed below the baseline for normal text.
QTextCharFormat::AlignMiddle 3 The center of the object is vertically aligned with the base line. Currently, this is only implemented for inline objects.
QTextCharFormat::AlignBottom 5 The bottom edge of the object is vertically aligned with the base line.
QTextCharFormat::AlignTop 4 The top edge of the object is vertically aligned with the base line.

Look up this member in the source code.

    Public Functions

    Toggle details QTextCharFormat

    QTextCharFormatQTextCharFormat () ()

    Constructs a new character format object.

    Look up this member in the source code.

    Toggle details QString QTextCharFormat

    anchorHrefanchorHref () ()const

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

    See also setAnchorHref().

    Look up this member in the source code.

    Toggle details QStringList QTextCharFormat

    anchorNamesanchorNames () ()const

    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.

    See also setAnchorNames().

    Look up this member in the source code.

    Toggle details QFont QTextCharFormat

    fontfont () ()const

    Returns the font for this character format.

    See also setFont().

    Look up this member in the source code.

    Toggle details QFont::Capitalization QTextCharFormat

    fontCapitalizationfontCapitalization () ()const

    Returns the current capitalization type of the font.

    See also setFontCapitalization().

    Look up this member in the source code.

    Toggle details QString QTextCharFormat

    fontFamilyfontFamily () ()const

    Returns the text format's font family.

    See also setFontFamily() and font().

    Look up this member in the source code.

    Toggle details bool QTextCharFormat

    fontFixedPitchfontFixedPitch () ()const

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

    See also setFontFixedPitch() and font().

    Look up this member in the source code.

    Toggle details bool QTextCharFormat

    fontItalicfontItalic () ()const

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

    See also setFontItalic() and font().

    Look up this member in the source code.

    Toggle details bool QTextCharFormat

    fontKerningfontKerning () ()const

    Returns true if the font kerning is enabled.

    See also setFontKerning() and font().

    Look up this member in the source code.

    Toggle details qreal QTextCharFormat

    fontLetterSpacingfontLetterSpacing () ()const

    Returns the current letter spacing percentage.

    See also setFontLetterSpacing().

    Look up this member in the source code.

    Toggle details bool QTextCharFormat

    fontOverlinefontOverline () ()const

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

    See also setFontOverline() and font().

    Look up this member in the source code.

    Toggle details qreal QTextCharFormat

    fontPointSizefontPointSize () ()const

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

    See also setFontPointSize() and font().

    Look up this member in the source code.

    Toggle details bool QTextCharFormat

    fontStrikeOutfontStrikeOut () ()const

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

    See also setFontStrikeOut() and font().

    Look up this member in the source code.

    Toggle details QFont::StyleHint QTextCharFormat

    fontStyleHintfontStyleHint () ()const

    Returns the font style hint.

    See also setFontStyleHint() and font().

    Look up this member in the source code.

    Toggle details QFont::StyleStrategy QTextCharFormat

    fontStyleStrategyfontStyleStrategy () ()const

    Returns the current font style strategy.

    See also setFontStyleStrategy() and font().

    Look up this member in the source code.

    Toggle details bool QTextCharFormat

    fontUnderlinefontUnderline () ()const

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

    See also setFontUnderline() and font().

    Look up this member in the source code.

    Toggle details int QTextCharFormat

    fontWeightfontWeight () ()const

    Returns the text format's font weight.

    See also setFontWeight(), font(), and QFont::Weight.

    Look up this member in the source code.

    Toggle details qreal QTextCharFormat

    fontWordSpacingfontWordSpacing () ()const

    Returns the current word spacing value.

    See also setFontWordSpacing().

    Look up this member in the source code.

    Toggle details bool QTextCharFormat

    isAnchorisAnchor () ()const

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

    See also setAnchor(), setAnchorHref(), and setAnchorNames().

    Look up this member in the source code.

    Toggle details bool QTextCharFormat

    isValidisValid () ()const

    Returns true if this character format is valid; otherwise returns false.

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setAnchorsetAnchor ( bool anchor ) ( bool anchor )

    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 setAnchorHref(), and optionally setAnchorNames() to create a hypertext link.

    See also isAnchor().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setAnchorHrefsetAnchorHref ( const QString &value ) ( const QString &value )

    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().

    See also anchorHref().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setAnchorNamessetAnchorNames ( const QStringList &names ) ( const QStringList &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().

    See also anchorNames().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontsetFont ( const QFont &font ) ( const QFont &font )

    Sets the text format's font.

    See also font().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontCapitalizationsetFontCapitalization ( QFont::Capitalization capitalization ...) ( QFont::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.

    See also fontCapitalization().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontFamilysetFontFamily ( const QString &family ) ( const QString &family )

    Sets the text format's font family.

    See also fontFamily() and setFont().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontFixedPitchsetFontFixedPitch ( bool fixedPitch ) ( bool fixedPitch )

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

    See also fontFixedPitch() and setFont().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontItalicsetFontItalic ( bool italic ) ( bool italic )

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

    See also fontItalic() and setFont().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontKerningsetFontKerning ( bool enable ) ( bool enable )

    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.

    See also fontKerning() and setFont().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontLetterSpacingsetFontLetterSpacing ( qreal spacing ) ( qreal spacing )

    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.

    See also fontLetterSpacing().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontOverlinesetFontOverline ( bool overline ) ( bool overline )

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

    See also fontOverline() and setFont().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontPointSizesetFontPointSize ( qreal size ) ( qreal size )

    Sets the text format's font size.

    See also fontPointSize() and setFont().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontStrikeOutsetFontStrikeOut ( bool strikeOut ) ( bool strikeOut )

    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.

    See also fontStrikeOut() and setFont().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontStyleHintsetFontStyleHint ( QFont::StyleHint hint , QFont::StyleStrategy strategy=QFont::PreferDefault ...) ( QFont::StyleHint hint , QFont::StyleStrategy strategy=QFont::PreferDefault )

    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.

    See also fontStyleHint(), setFont(), and QFont::setStyleHint().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontStyleStrategysetFontStyleStrategy ( QFont::StyleStrategy strategy ...) ( QFont::StyleStrategy strategy )

    Sets the font style strategy.

    See also fontStyleStrategy(), setFont(), and QFont::setStyleStrategy().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontUnderlinesetFontUnderline ( bool underline ) ( bool underline )

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

    See also fontUnderline() and setFont().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontWeightsetFontWeight ( int weight ) ( int weight )

    Sets the text format's font weight to weight.

    See also fontWeight(), setFont(), and QFont::Weight.

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setFontWordSpacingsetFontWordSpacing ( qreal spacing ) ( qreal spacing )

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

    See also fontWordSpacing().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setTextOutlinesetTextOutline ( const QPen &pen ) ( const QPen &pen )

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

    See also textOutline().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setToolTipsetToolTip ( const QString &text ) ( const QString &text )

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

    See also toolTip().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setUnderlineColorsetUnderlineColor ( const QColor &color ) ( const QColor &color )

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

    See also underlineColor().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setUnderlineStylesetUnderlineStyle ( UnderlineStyle style ) ( UnderlineStyle style )

    Sets the style of underlining the text to style.

    See also underlineStyle().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setVerticalAlignmentsetVerticalAlignment ( VerticalAlignment alignment ...) ( VerticalAlignment alignment )

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

    See also verticalAlignment().

    Look up this member in the source code.

    Toggle details QPen QTextCharFormat

    textOutlinetextOutline () ()const

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

    See also setTextOutline().

    Look up this member in the source code.

    Toggle details QString QTextCharFormat

    toolTiptoolTip () ()const

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

    See also setToolTip().

    Look up this member in the source code.

    Toggle details QColor QTextCharFormat

    underlineColorunderlineColor () ()const

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

    See also setUnderlineColor().

    Look up this member in the source code.

    Toggle details UnderlineStyle QTextCharFormat

    underlineStyleunderlineStyle () ()const

    Returns the style of underlining the text.

    See also setUnderlineStyle().

    Look up this member in the source code.

    Toggle details VerticalAlignment QTextCharFormat

    verticalAlignmentverticalAlignment () ()const

    Returns the vertical alignment used for characters with this format.

    See also setVerticalAlignment().

    Look up this member in the source code.

    Toggle details QString QTextCharFormat

    anchorNameanchorName () ()const Obsolete function

    This function is deprecated. Use anchorNames() instead.

    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.

    See also setAnchorName().

    Look up this member in the source code.

    Toggle details void QTextCharFormat

    setAnchorNamesetAnchorName ( const QString &name ) ( const QString &name ) Obsolete function

    This function is deprecated. Use setAnchorNames() instead.

    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().

    See also anchorName().

    Look up this member in the source code.

    Notes provided by the Qt Community

    No notes