QTextCharFormat Class

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

Header: #include <QTextCharFormat>
qmake: QT += gui
Inherits: QTextFormat
Inherited By:

QTextImageFormat and QTextTableCellFormat

Note: All functions in this class are reentrant.

Public Types

enum FontPropertiesInheritanceBehavior { FontPropertiesSpecifiedOnly, FontPropertiesAll }
enum UnderlineStyle { NoUnderline, SingleUnderline, DashUnderline, DotLine, ..., SpellCheckUnderline }
enum VerticalAlignment { AlignNormal, AlignSuperScript, AlignSubScript, AlignMiddle, ..., AlignBaseline }

Public Functions

QTextCharFormat()
QString anchorHref() const
QString anchorName() const
QStringList anchorNames() const
QFont font() const
QFont::Capitalization fontCapitalization() const
QString fontFamily() const
bool fontFixedPitch() const
QFont::HintingPreference fontHintingPreference() const
bool fontItalic() const
bool fontKerning() const
qreal fontLetterSpacing() const
QFont::SpacingType fontLetterSpacingType() const
bool fontOverline() const
qreal fontPointSize() const
int fontStretch() const
bool fontStrikeOut() const
QFont::StyleHint fontStyleHint() const
QFont::StyleStrategy fontStyleStrategy() const
bool fontUnderline() const
int fontWeight() const
qreal fontWordSpacing() const
bool isAnchor() const
bool isValid() const
void setAnchor(bool anchor)
void setAnchorHref(const QString &value)
void setAnchorName(const QString &name)
void setAnchorNames(const QStringList &names)
void setFont(const QFont &font, QTextCharFormat::FontPropertiesInheritanceBehavior behavior)
void setFont(const QFont &font)
void setFontCapitalization(QFont::Capitalization capitalization)
void setFontFamily(const QString &family)
void setFontFixedPitch(bool fixedPitch)
void setFontHintingPreference(QFont::HintingPreference hintingPreference)
void setFontItalic(bool italic)
void setFontKerning(bool enable)
void setFontLetterSpacing(qreal spacing)
void setFontLetterSpacingType(QFont::SpacingType letterSpacingType)
void setFontOverline(bool overline)
void setFontPointSize(qreal size)
void setFontStretch(int factor)
void setFontStrikeOut(bool strikeOut)
void setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy = QFont::PreferDefault)
void setFontStyleStrategy(QFont::StyleStrategy strategy)
void setFontUnderline(bool underline)
void setFontWeight(int weight)
void setFontWordSpacing(qreal spacing)
void setTableCellColumnSpan(int tableCellColumnSpan)
void setTableCellRowSpan(int tableCellRowSpan)
void setTextOutline(const QPen &pen)
void setToolTip(const QString &tip)
void setUnderlineColor(const QColor &color)
void setUnderlineStyle(QTextCharFormat::UnderlineStyle style)
void setVerticalAlignment(QTextCharFormat::VerticalAlignment alignment)
int tableCellColumnSpan() const
int tableCellRowSpan() const
QPen textOutline() const
QString toolTip() const
QColor underlineColor() const
QTextCharFormat::UnderlineStyle underlineStyle() const
QTextCharFormat::VerticalAlignment verticalAlignment() const

Protected Functions

QTextCharFormat(const QTextFormat &fmt)

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.

Member Type Documentation

enum QTextCharFormat::FontPropertiesInheritanceBehavior

This enum specifies how the setFont() function should behave with respect to unset font properties.

ConstantValueDescription
QTextCharFormat::FontPropertiesSpecifiedOnly0If a property is not explicitly set, do not change the text format's property value.
QTextCharFormat::FontPropertiesAll1If a property is not explicitly set, override the text format's property with a default value.

This enum was introduced or modified in Qt 5.3.

See also setFont().

enum QTextCharFormat::UnderlineStyle

This enum describes the different ways drawing underlined text.

ConstantValueDescription
QTextCharFormat::NoUnderline0Text is draw without any underlining decoration.
QTextCharFormat::SingleUnderline1A line is drawn using Qt::SolidLine.
QTextCharFormat::DashUnderline2Dashes are drawn using Qt::DashLine.
QTextCharFormat::DotLine3Dots are drawn using Qt::DotLine;
QTextCharFormat::DashDotLine4Dashs and dots are drawn using Qt::DashDotLine.
QTextCharFormat::DashDotDotLine5Underlines draw drawn using Qt::DashDotDotLine.
QTextCharFormat::WaveUnderline6The text is underlined using a wave shaped line.
QTextCharFormat::SpellCheckUnderline7The underline is drawn depending on the SpellCheckUnderlineStyle theme hint of QPlatformTheme. By default this is mapped to WaveUnderline, on macOS it is mapped to DotLine.

See also Qt::PenStyle.

enum QTextCharFormat::VerticalAlignment

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

ConstantValueDescription
QTextCharFormat::AlignNormal0Adjacent characters are positioned in the standard way for text in the writing system in use.
QTextCharFormat::AlignSuperScript1Characters are placed above the base line for normal text.
QTextCharFormat::AlignSubScript2Characters are placed below the base line for normal text.
QTextCharFormat::AlignMiddle3The center of the object is vertically aligned with the base line. Currently, this is only implemented for inline objects.
QTextCharFormat::AlignBottom5The bottom edge of the object is vertically aligned with the base line.
QTextCharFormat::AlignTop4The top edge of the object is vertically aligned with the base line.
QTextCharFormat::AlignBaseline6The base lines of the characters are aligned.

Member Function Documentation

QTextCharFormat::QTextCharFormat()

Default constructs an instance of QTextCharFormat.

[protected] QTextCharFormat::QTextCharFormat(const QTextFormat &fmt)

Default constructs an instance of QTextCharFormat.

QString QTextCharFormat::anchorHref() const

See also setAnchorHref().

QString QTextCharFormat::anchorName() const

See also setAnchorName().

QStringList QTextCharFormat::anchorNames() const

See also setAnchorNames().

QFont QTextCharFormat::font() const

Returns the font for this character format.

See also setFont().

QFont::Capitalization QTextCharFormat::fontCapitalization() const

See also setFontCapitalization().

QString QTextCharFormat::fontFamily() const

See also setFontFamily().

bool QTextCharFormat::fontFixedPitch() const

See also setFontFixedPitch().

QFont::HintingPreference QTextCharFormat::fontHintingPreference() const

See also setFontHintingPreference().

bool QTextCharFormat::fontItalic() const

See also setFontItalic().

bool QTextCharFormat::fontKerning() const

See also setFontKerning().

qreal QTextCharFormat::fontLetterSpacing() const

See also setFontLetterSpacing().

QFont::SpacingType QTextCharFormat::fontLetterSpacingType() const

See also setFontLetterSpacingType().

bool QTextCharFormat::fontOverline() const

See also setFontOverline().

qreal QTextCharFormat::fontPointSize() const

See also setFontPointSize().

int QTextCharFormat::fontStretch() const

See also setFontStretch().

bool QTextCharFormat::fontStrikeOut() const

See also setFontStrikeOut().

QFont::StyleHint QTextCharFormat::fontStyleHint() const

See also setFontStyleHint().

QFont::StyleStrategy QTextCharFormat::fontStyleStrategy() const

See also setFontStyleStrategy().

bool QTextCharFormat::fontUnderline() const

See also setFontUnderline().

int QTextCharFormat::fontWeight() const

See also setFontWeight().

qreal QTextCharFormat::fontWordSpacing() const

See also setFontWordSpacing().

bool QTextCharFormat::isAnchor() const

bool QTextCharFormat::isValid() const

void QTextCharFormat::setAnchor(bool anchor)

See also isAnchor().

void QTextCharFormat::setAnchorHref(const QString &value)

See also anchorHref().

void QTextCharFormat::setAnchorName(const QString &name)

See also anchorName().

void QTextCharFormat::setAnchorNames(const QStringList &names)

See also anchorNames().

void QTextCharFormat::setFont(const QFont &font, QTextCharFormat::FontPropertiesInheritanceBehavior behavior)

Sets the text format's font.

If behavior is QTextCharFormat::FontPropertiesAll, the font property that has not been explicitly set is treated like as it were set with default value; If behavior is QTextCharFormat::FontPropertiesSpecifiedOnly, the font property that has not been explicitly set is ignored and the respective property value remains unchanged.

This function was introduced in Qt 5.3.

See also font().

void QTextCharFormat::setFont(const QFont &font)

This is an overloaded function.

Sets the text format's font.

See also font().

void QTextCharFormat::setFontCapitalization(QFont::Capitalization capitalization)

See also fontCapitalization().

void QTextCharFormat::setFontFamily(const QString &family)

See also fontFamily().

void QTextCharFormat::setFontFixedPitch(bool fixedPitch)

See also fontFixedPitch().

void QTextCharFormat::setFontHintingPreference(QFont::HintingPreference hintingPreference)

See also fontHintingPreference().

void QTextCharFormat::setFontItalic(bool italic)

See also fontItalic().

void QTextCharFormat::setFontKerning(bool enable)

See also fontKerning().

void QTextCharFormat::setFontLetterSpacing(qreal spacing)

See also fontLetterSpacing().

void QTextCharFormat::setFontLetterSpacingType(QFont::SpacingType letterSpacingType)

See also fontLetterSpacingType().

void QTextCharFormat::setFontOverline(bool overline)

See also fontOverline().

void QTextCharFormat::setFontPointSize(qreal size)

See also fontPointSize().

void QTextCharFormat::setFontStretch(int factor)

See also fontStretch().

void QTextCharFormat::setFontStrikeOut(bool strikeOut)

See also fontStrikeOut().

void QTextCharFormat::setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy = QFont::PreferDefault)

See also fontStyleHint().

void QTextCharFormat::setFontStyleStrategy(QFont::StyleStrategy strategy)

See also fontStyleStrategy().

void QTextCharFormat::setFontUnderline(bool underline)

See also fontUnderline().

void QTextCharFormat::setFontWeight(int weight)

See also fontWeight().

void QTextCharFormat::setFontWordSpacing(qreal spacing)

See also fontWordSpacing().

void QTextCharFormat::setTableCellColumnSpan(int tableCellColumnSpan)

See also tableCellColumnSpan().

void QTextCharFormat::setTableCellRowSpan(int tableCellRowSpan)

See also tableCellRowSpan().

void QTextCharFormat::setTextOutline(const QPen &pen)

See also textOutline().

void QTextCharFormat::setToolTip(const QString &tip)

See also toolTip().

void QTextCharFormat::setUnderlineColor(const QColor &color)

See also underlineColor().

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

See also underlineStyle().

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

See also verticalAlignment().

int QTextCharFormat::tableCellColumnSpan() const

See also setTableCellColumnSpan().

int QTextCharFormat::tableCellRowSpan() const

See also setTableCellRowSpan().

QPen QTextCharFormat::textOutline() const

See also setTextOutline().

QString QTextCharFormat::toolTip() const

See also setToolTip().

QColor QTextCharFormat::underlineColor() const

See also setUnderlineColor().

QTextCharFormat::UnderlineStyle QTextCharFormat::underlineStyle() const

See also setUnderlineStyle().

QTextCharFormat::VerticalAlignment QTextCharFormat::verticalAlignment() const

See also setVerticalAlignment().