QTextCharFormat Class
The QTextCharFormat class provides formatting information for characters in a QTextDocument. More...
Header: | #include <QTextCharFormat> |
qmake: | QT += gui |
Inherits: | QTextFormat |
Inherited By: |
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
QFont | font() const |
void | setFont(const QFont &font, QTextCharFormat::FontPropertiesInheritanceBehavior behavior) |
void | setFont(const QFont &font) |
- 27 public functions inherited from QTextFormat
Detailed Description
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.
Constant | Value | Description |
---|---|---|
QTextCharFormat::FontPropertiesSpecifiedOnly | 0 | If a property is not explicitly set, do not change the text format's property value. |
QTextCharFormat::FontPropertiesAll | 1 | If 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.
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 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.
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. |
Member Function Documentation
QFont QTextCharFormat::font() const
Returns the font for this character format.
See also setFont().
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().