|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# QTextCharFormat Class Reference
[QtGui module]

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

     #include <QTextCharFormat>

Inherits QTextFormat.

Inherited by QTextImageFormat.

- List of all members, including inherited members

### Public Types

- enum UnderlineStyle { NoUnderline, SingleUnderline, DashUnderline, DotLine, ..., SpellCheckUnderline }
- enum VerticalAlignment { AlignNormal, AlignSuperScript, AlignSubScript }

### Public Functions

- QTextCharFormat ()
- QString anchorHref () const
- QString anchorName () const
- QFont font () const
- QString fontFamily () const
- bool fontFixedPitch () const
- bool fontItalic () const
- bool fontOverline () const
- qreal fontPointSize () const
- bool fontStrikeOut () const
- bool fontUnderline () const
- int fontWeight () const
- bool isAnchor () const
- bool isValid () const
- void setAnchor ( bool anchor )
- void setAnchorHref ( const QString & value )
- void setAnchorName ( const QString & name )
- void setFont ( const QFont & font )
- void setFontFamily ( const QString & family )
- void setFontFixedPitch ( bool fixedPitch )
- void setFontItalic ( bool italic )
- void setFontOverline ( bool overline )
- void setFontPointSize ( qreal size )
- void setFontStrikeOut ( bool strikeOut )
- void setFontUnderline ( bool underline )
- void setFontWeight ( int weight )
- void setTableCellColumnSpan ( int tableCellColumnSpan )
- void setTableCellRowSpan ( int tableCellRowSpan )
- void setTextOutline ( const QPen & pen )
- void setUnderlineColor ( const QColor & color )
- void setUnderlineStyle ( UnderlineStyle style )
- void setVerticalAlignment ( VerticalAlignment alignment )
- int tableCellColumnSpan () const
- int tableCellRowSpan () const
- QPen textOutline () const
- QColor underlineColor () const
- UnderlineStyle underlineStyle () const
- VerticalAlignment verticalAlignment () const

- 46 public functions inherited from QTextFormat

## 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 setAnchorName() functions are used to specify the information about the hyperlink's destination and the anchor's name.

If the text is written within a table, it can be made to span a number of rows and columns with the setTableCellRowSpan() and setTableCellColumnSpan() functions.

See also QTextFormat, QTextBlockFormat, QTextTableFormat, and QTextListFormat.

## Member Type Documentation

### enum QTextCharFormat::UnderlineStyle

This enum describes the different ways drawing underlined text.

Constant | Value | Description
--- | --- | ---
`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.

### enum QTextCharFormat::VerticalAlignment

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

Constant | Value | Description
--- | --- | ---
`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.

## Member Function Documentation

### QTextCharFormat::QTextCharFormat ()

Constructs a new character format object.

### QString QTextCharFormat::anchorHref () const

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

See also setAnchorHref().

### QString QTextCharFormat::anchorName () const

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

### QFont QTextCharFormat::font () const

Returns the font for this character format.

See also setFont().

### QString QTextCharFormat::fontFamily () const

Returns the text format's font family.

See also setFontFamily() and font().

### bool QTextCharFormat::fontFixedPitch () const

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

See also setFontFixedPitch() and font().

### bool QTextCharFormat::fontItalic () const

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

See also setFontItalic() and font().

### bool QTextCharFormat::fontOverline () const

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

See also setFontOverline() and font().

### qreal QTextCharFormat::fontPointSize () const

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

See also setFontPointSize() and font().

### bool QTextCharFormat::fontStrikeOut () 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().

### bool QTextCharFormat::fontUnderline () const

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

See also setFontUnderline() and font().

### int QTextCharFormat::fontWeight () const

Returns the text format's font weight.

See also setFontWeight() and font().

### bool QTextCharFormat::isAnchor () const

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

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

### bool QTextCharFormat::isValid () const

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

### void QTextCharFormat::setAnchor ( 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 setAnchorName() to create a hypertext link.

See also isAnchor().

### void QTextCharFormat::setAnchorHref ( const QString & value )

Sets the hypertext link for the text format to the given value. This is typically a URL like "http://www.trolltech.com/index.html".

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

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

See also anchorHref().

### void QTextCharFormat::setAnchorName ( const QString & name )

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

### void QTextCharFormat::setFont ( const QFont & font )

Sets the text format's font.

See also font().

### void QTextCharFormat::setFontFamily ( const QString & family )

Sets the text format's font family.

See also fontFamily() and setFont().

### void QTextCharFormat::setFontFixedPitch ( 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().

### void QTextCharFormat::setFontItalic ( 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().

### void QTextCharFormat::setFontOverline ( 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().

### void QTextCharFormat::setFontPointSize ( qreal size )

Sets the text format's font size.

See also fontPointSize() and setFont().

### void QTextCharFormat::setFontStrikeOut ( 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().

### void QTextCharFormat::setFontUnderline ( 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().

### void QTextCharFormat::setFontWeight ( int weight )

Sets the text format's font weight to weight.

See also fontWeight() and setFont().

### void QTextCharFormat::setTableCellColumnSpan ( int tableCellColumnSpan )

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

See also tableCellColumnSpan().

### void QTextCharFormat::setTableCellRowSpan ( int tableCellRowSpan )

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

See also tableCellRowSpan().

### void QTextCharFormat::setTextOutline ( const QPen & pen )

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

See also textOutline().

### void QTextCharFormat::setUnderlineColor ( const QColor & color )

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

See also underlineColor().

### void QTextCharFormat::setUnderlineStyle ( UnderlineStyle style )

Sets the style of underlining the text to style.

This function was introduced in Qt 4.2.

See also underlineStyle().

### void QTextCharFormat::setVerticalAlignment ( VerticalAlignment alignment )

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

See also verticalAlignment().

### int QTextCharFormat::tableCellColumnSpan () const

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.

See also setTableCellColumnSpan().

### int QTextCharFormat::tableCellRowSpan () const

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.

See also setTableCellRowSpan().

### QPen QTextCharFormat::textOutline () const

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

See also setTextOutline().

### QColor QTextCharFormat::underlineColor () const

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

See also setUnderlineColor().

### UnderlineStyle QTextCharFormat::underlineStyle () const

Returns the style of underlining the text.

This function was introduced in Qt 4.2.

See also setUnderlineStyle().

### VerticalAlignment QTextCharFormat::verticalAlignment () const

Returns the vertical alignment used for characters with this format.

See also setVerticalAlignment().