
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQTextCharFormat class provides formatting information for characters in aQTextDocument.More...
| Header: | #include <QTextCharFormat> |
| Inherits: | QTextFormat |
| Inherited By: |
Note: All functions in this class arereentrant.
| enum | UnderlineStyle { NoUnderline, SingleUnderline, DashUnderline, DotLine, ..., SpellCheckUnderline } |
| enum | VerticalAlignment { AlignNormal, AlignSuperScript, AlignSubScript, AlignMiddle, ..., AlignBaseline } |
| QTextCharFormat() | |
| QString | anchorHref() 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 |
| bool | fontOverline() const |
| qreal | fontPointSize() 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 | setAnchorNames(const QStringList & names) |
| 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 | setFontOverline(bool overline) |
| void | setFontPointSize(qreal size) |
| 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 | setTextOutline(const QPen & pen) |
| void | setToolTip(const QString & text) |
| void | setUnderlineColor(const QColor & color) |
| void | setUnderlineStyle(UnderlineStyle style) |
| void | setVerticalAlignment(VerticalAlignment alignment) |
| QPen | textOutline() const |
| QString | toolTip() const |
| QColor | underlineColor() const |
| UnderlineStyle | underlineStyle() const |
| VerticalAlignment | verticalAlignment() const |
TheQTextCharFormat class provides formatting information for characters in aQTextDocument.
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 thesetFont() function, and each aspect of its appearance can be adjusted to give the desired effect.setFontFamily() andsetFontPointSize() define the font's family (e.g. Times) and printed size;setFontWeight() andsetFontItalic() provide control over the style of the font.setFontUnderline(),setFontOverline(),setFontStrikeOut(), andsetFontFixedPitch() provide additional effects for text.
The color is set withsetForeground(). If the text is intended to be used as an anchor (for hyperlinks), this can be enabled withsetAnchor(). ThesetAnchorHref() andsetAnchorNames() functions are used to specify the information about the hyperlink's destination and the anchor's name.
See alsoQTextFormat,QTextBlockFormat,QTextTableFormat, andQTextListFormat.
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 usingQt::SolidLine. |
QTextCharFormat::DashUnderline | 2 | Dashes are drawn usingQt::DashLine. |
QTextCharFormat::DotLine | 3 | Dots are drawn usingQt::DotLine; |
QTextCharFormat::DashDotLine | 4 | Dashs and dots are drawn usingQt::DashDotLine. |
QTextCharFormat::DashDotDotLine | 5 | Underlines draw drawn usingQt::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 theQApplication style. By default this is mapped to WaveUnderline, on Mac OS X it is mapped to DashDotLine. |
See alsoQt::PenStyle.
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 base line for normal text. |
QTextCharFormat::AlignSubScript | 2 | Characters are placed below the base line 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. |
QTextCharFormat::AlignBaseline | 6 | The base lines of the characters are aligned. |
Constructs a new character format object.
Returns the text format's hypertext link, or an empty string if none has been set.
See alsosetAnchorHref().
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.
This function was introduced in Qt 4.3.
See alsosetAnchorNames().
Returns the font for this character format.
See alsosetFont().
Returns the current capitalization type of the font.
This function was introduced in Qt 4.4.
See alsosetFontCapitalization().
Returns the text format's font family.
See alsosetFontFamily() andfont().
Returns true if the text format's font is fixed pitch; otherwise returns false.
See alsosetFontFixedPitch() andfont().
Returns the hinting preference set for this text format.
This function was introduced in Qt 4.8.
See alsosetFontHintingPreference(),font(), andQFont::hintingPreference().
Returns true if the text format's font is italic; otherwise returns false.
See alsosetFontItalic() andfont().
Returns true if the font kerning is enabled.
This function was introduced in Qt 4.5.
See alsosetFontKerning() andfont().
Returns the current letter spacing percentage.
This function was introduced in Qt 4.4.
See alsosetFontLetterSpacing().
Returns true if the text format's font is overlined; otherwise returns false.
See alsosetFontOverline() andfont().
Returns the font size used to display text in this format.
See alsosetFontPointSize() andfont().
Returns true if the text format's font is struck out (has a horizontal line drawn through it); otherwise returns false.
See alsosetFontStrikeOut() andfont().
Returns the font style hint.
This function was introduced in Qt 4.5.
See alsosetFontStyleHint() andfont().
Returns the current font style strategy.
This function was introduced in Qt 4.5.
See alsosetFontStyleStrategy() andfont().
Returns true if the text format's font is underlined; otherwise returns false.
See alsosetFontUnderline() andfont().
Returns the text format's font weight.
See alsosetFontWeight(),font(), andQFont::Weight.
Returns the current word spacing value.
This function was introduced in Qt 4.4.
See alsosetFontWordSpacing().
Returns true if the text is formatted as an anchor; otherwise returns false.
See alsosetAnchor(),setAnchorHref(), andsetAnchorNames().
Returns true if this character format is valid; otherwise returns false.
Ifanchor 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. UsesetAnchorHref(), and optionallysetAnchorNames() to create a hypertext link.
See alsoisAnchor().
Sets the hypertext link for the text format to the givenvalue. This is typically a URL like "http://example.com/index.html".
The anchor will be displayed with thevalue as its display text; if you want to display different text callsetAnchorNames().
To format the text as a hypertext link usesetAnchor().
See alsoanchorHref().
Sets the text format's anchornames. For the anchor to work as a hyperlink, the destination must be set withsetAnchorHref() and the anchor must be enabled withsetAnchor().
This function was introduced in Qt 4.3.
See alsoanchorNames().
Sets the text format'sfont.
See alsofont().
Sets the capitalization of the text that apppears in this font tocapitalization.
A font's capitalization makes the text appear in the selected capitalization mode.
This function was introduced in Qt 4.4.
See alsofontCapitalization().
Sets the text format's fontfamily.
See alsofontFamily() andsetFont().
IffixedPitch is true, sets the text format's font to be fixed pitch; otherwise a non-fixed pitch font is used.
See alsofontFixedPitch() andsetFont().
Sets the hinting preference of the text format's font to behintingPreference.
This function was introduced in Qt 4.8.
See alsofontHintingPreference(),setFont(), andQFont::setHintingPreference().
Ifitalic is true, sets the text format's font to be italic; otherwise the font will be non-italic.
See alsofontItalic() andsetFont().
Enables kerning for this font ifenable 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.
This function was introduced in Qt 4.5.
See alsofontKerning() andsetFont().
Sets the letter spacing of this format to the givenspacing, in percent. A value of 100 indicates default spacing; a value of 200 doubles the amount of space a letter takes.
This function was introduced in Qt 4.4.
See alsofontLetterSpacing().
Ifoverline is true, sets the text format's font to be overlined; otherwise the font is displayed non-overlined.
See alsofontOverline() andsetFont().
Sets the text format's fontsize.
See alsofontPointSize() andsetFont().
IfstrikeOut 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 alsofontStrikeOut() andsetFont().
Sets the font stylehint andstrategy.
Qt does not support style hints on X11 since this information is not provided by the window system.
This function was introduced in Qt 4.5.
See alsofontStyleHint(),setFont(), andQFont::setStyleHint().
Sets the font stylestrategy.
This function was introduced in Qt 4.5.
See alsofontStyleStrategy(),setFont(), andQFont::setStyleStrategy().
Ifunderline is true, sets the text format's font to be underlined; otherwise it is displayed non-underlined.
See alsofontUnderline() andsetFont().
Sets the text format's font weight toweight.
See alsofontWeight(),setFont(), andQFont::Weight.
Sets the word spacing of this format to the givenspacing, in pixels.
This function was introduced in Qt 4.4.
See alsofontWordSpacing().
Sets the pen used to draw the outlines of characters to the givenpen.
See alsotextOutline().
Sets the tool tip for a fragment of text to the giventext.
This function was introduced in Qt 4.3.
See alsotoolTip().
Sets the underline color used for the characters with this format to thecolor specified.
See alsounderlineColor().
Sets the style of underlining the text tostyle.
This function was introduced in Qt 4.2.
See alsounderlineStyle().
Sets the vertical alignment used for the characters with this format to thealignment specified.
See alsoverticalAlignment().
Returns the pen used to draw the outlines of characters in this format.
See alsosetTextOutline().
Returns the tool tip that is displayed for a fragment of text.
This function was introduced in Qt 4.3.
See alsosetToolTip().
Returns the color used to underline the characters with this format.
See alsosetUnderlineColor().
Returns the style of underlining the text.
This function was introduced in Qt 4.2.
See alsosetUnderlineStyle().
Returns the vertical alignment used for characters with this format.
See alsosetVerticalAlignment().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.