QTextCharFormat 類為字符提供格式化信息在 QTextDocument . 更多...
| 頭: | #include <QTextCharFormat> |
| qmake: | QT += gui |
| 繼承: | QTextFormat |
| 繼承者: |
注意: 此類的所有函數 可重入 .
| enum | FontPropertiesInheritanceBehavior { FontPropertiesSpecifiedOnly, FontPropertiesAll } |
| enum | UnderlineStyle { NoUnderline, SingleUnderline, DashUnderline, DotLine, DashDotLine, …, SpellCheckUnderline } |
| enum | VerticalAlignment { AlignNormal, AlignSuperScript, AlignSubScript, AlignMiddle, AlignBottom, …, AlignBaseline } |
| QTextCharFormat () | |
| QString | anchorHref () const |
| QStringList | anchorNames () const |
| QFont | font () const |
| QFont::Capitalization | fontCapitalization () const |
| QVariant | fontFamilies () 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 |
| QVariant | fontStyleName () 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 & 名稱 ) |
| void | setFont (const QFont & font , QTextCharFormat::FontPropertiesInheritanceBehavior behavior ) |
| void | setFont (const QFont & font ) |
| void | setFontCapitalization (QFont::Capitalization capitalization ) |
| void | setFontFamilies (const QStringList & families ) |
| 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 | setFontStyleName (const QString & styleName ) |
| 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 (QTextCharFormat::UnderlineStyle style ) |
| void | setVerticalAlignment (QTextCharFormat::VerticalAlignment alignment ) |
| QPen | textOutline () const |
| QString | toolTip () const |
| QColor | underlineColor () const |
| QTextCharFormat::UnderlineStyle | underlineStyle () const |
| QTextCharFormat::VerticalAlignment | verticalAlignment () const |
文檔中文本的字符格式指定文本的視覺特性,及在超文本文檔中其角色的有關信息。
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 () 和 setFontPointSize () define the font's family (e.g. Times) and printed size; setFontWeight () 和 setFontItalic () provide control over the style of the font. setFontUnderline (), setFontOverline (), setFontStrikeOut (),和 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 ()。 setAnchorHref () 和 setAnchorNames () functions are used to specify the information about the hyperlink's destination and the anchor's name.
另請參閱 QTextFormat , QTextBlockFormat , QTextTableFormat ,和 QTextListFormat .
This enum specifies how the setFont () function should behave with respect to unset font properties.
| 常量 | 值 | 描述 |
|---|---|---|
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. |
該枚舉在 Qt 5.3 引入或被修改。
另請參閱 setFont ().
This enum describes the different ways drawing underlined text.
| 常量 | 值 | 描述 |
|---|---|---|
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. |
另請參閱 Qt::PenStyle .
This enum describes the ways that adjacent characters can be vertically aligned.
| 常量 | 值 | 描述 |
|---|---|---|
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. |
構造新的字符格式對象。
返迴文本格式的超文本鏈接,或空字符串若未設置。
另請參閱 setAnchorHref ().
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.
該函數在 Qt 4.3 引入。
另請參閱 setAnchorNames ().
Returns the font for this character format.
另請參閱 setFont ().
返迴字體的當前大寫類型。
該函數在 Qt 4.4 引入。
另請參閱 setFontCapitalization ().
Returns the text format's font families.
該函數在 Qt 5.13 引入。
另請參閱 setFontFamilies () 和 font ().
Returns the text format's font family.
另請參閱 setFontFamily () 和 font ().
返迴
true
if the text format's font is fixed pitch; otherwise returns
false
.
另請參閱 setFontFixedPitch () 和 font ().
Returns the hinting preference set for this text format.
該函數在 Qt 4.8 引入。
另請參閱 setFontHintingPreference (), font (),和 QFont::hintingPreference ().
返迴
true
if the text format's font is italic; otherwise returns
false
.
另請參閱 setFontItalic () 和 font ().
返迴
true
if the font kerning is enabled.
該函數在 Qt 4.5 引入。
另請參閱 setFontKerning () 和 font ().
Returns the current letter spacing.
該函數在 Qt 4.4 引入。
另請參閱 setFontLetterSpacing (), setFontLetterSpacingType (),和 fontLetterSpacingType ().
Returns the letter spacing type of this format..
該函數在 Qt 5.0 引入。
另請參閱 setFontLetterSpacingType (), setFontLetterSpacing (),和 fontLetterSpacing ().
返迴
true
if the text format's font is overlined; otherwise returns
false
.
另請參閱 setFontOverline () 和 font ().
Returns the font size used to display text in this format.
另請參閱 setFontPointSize () 和 font ().
Returns the current font stretching.
該函數在 Qt 5.0 引入。
另請參閱 setFontStretch ().
返迴
true
if the text format's font is struck out (has a horizontal line drawn through it); otherwise returns
false
.
另請參閱 setFontStrikeOut () 和 font ().
Returns the font style hint.
該函數在 Qt 4.5 引入。
另請參閱 setFontStyleHint () 和 font ().
Returns the text format's font style name.
該函數在 Qt 5.13 引入。
另請參閱 setFontStyleName (), font (),和 QFont::styleName ().
返迴當前字體樣式對策。
該函數在 Qt 4.5 引入。
另請參閱 setFontStyleStrategy () 和 font ().
返迴
true
若文本格式的字體帶下劃綫;否則返迴
false
.
另請參閱 setFontUnderline () 和 font ().
返迴文本格式的字體粗細。
另請參閱 setFontWeight (), font (),和 QFont::Weight .
返迴當前單詞的間距值。
該函數在 Qt 4.4 引入。
另請參閱 setFontWordSpacing ().
返迴
true
if the text is formatted as an anchor; otherwise returns
false
.
另請參閱 setAnchor (), setAnchorHref (),和 setAnchorNames ().
返迴
true
if this character format is valid; otherwise returns false.
若 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.
另請參閱 isAnchor ().
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 ().
另請參閱 anchorHref ().
設置文本格式的錨點 名稱 . For the anchor to work as a hyperlink, the destination must be set with setAnchorHref () and the anchor must be enabled with setAnchor ().
該函數在 Qt 4.3 引入。
另請參閱 anchorNames ().
設置文本格式的 font .
若 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.
該函數在 Qt 5.3 引入。
另請參閱 font ().
這是重載函數。
設置文本格式的 font .
另請參閱 font ().
Sets the capitalization of the text that apppears in this font to capitalization .
字體大寫使文本以選中大寫模式齣現。
該函數在 Qt 4.4 引入。
另請參閱 fontCapitalization ().
設置文本格式的字體 families .
該函數在 Qt 5.13 引入。
另請參閱 fontFamilies () 和 setFont ().
設置文本格式的字體 family .
另請參閱 fontFamily () 和 setFont ().
若 fixedPitch is true, sets the text format's font to be fixed pitch; otherwise a non-fixed pitch font is used.
另請參閱 fontFixedPitch () 和 setFont ().
Sets the hinting preference of the text format's font to be hintingPreference .
該函數在 Qt 4.8 引入。
另請參閱 fontHintingPreference (), setFont (),和 QFont::setHintingPreference ().
若 italic is true, sets the text format's font to be italic; otherwise the font will be non-italic.
另請參閱 fontItalic () 和 setFont ().
為此字體啓用字距調整,若 enable 為 true;否則禁用它。
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.
該函數在 Qt 4.5 引入。
另請參閱 fontKerning () 和 setFont ().
Sets the letter spacing of this format to the given spacing . The meaning of the value depends on the font letter spacing type.
For percentage spacing a value of 100 indicates default spacing; a value of 200 doubles the amount of space a letter takes.
該函數在 Qt 4.4 引入。
另請參閱 fontLetterSpacing (), setFontLetterSpacingType (),和 fontLetterSpacingType ().
將此格式的字母間距類型設為 letterSpacingType .
該函數在 Qt 5.0 引入。
另請參閱 fontLetterSpacingType (), setFontLetterSpacing (),和 fontLetterSpacing ().
若 overline is true, sets the text format's font to be overlined; otherwise the font is displayed non-overlined.
另請參閱 fontOverline () 和 setFont ().
設置文本格式的字體 size .
另請參閱 fontPointSize () 和 setFont ().
Sets the stretch factor for the font to factor .
The stretch factor changes the width of all characters in the font by factor percent. For example, setting factor to 150 results in all characters in the font being 1.5 times (ie. 150%) wider. The default stretch factor is 100. The minimum stretch factor is 1, and the maximum stretch factor is 4000.
拉伸因子僅應用於輪廓字體。位圖字體會忽略拉伸因子。
該函數在 Qt 5.0 引入。
另請參閱 fontStretch ().
若 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.
另請參閱 fontStrikeOut () 和 setFont ().
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.
該函數在 Qt 4.5 引入。
另請參閱 fontStyleHint (), setFont (),和 QFont::setStyleHint ().
設置文本格式的字體 styleName .
該函數在 Qt 5.13 引入。
另請參閱 fontStyleName (), setFont (),和 QFont::setStyleName ().
Sets the font style strategy .
該函數在 Qt 4.5 引入。
另請參閱 fontStyleStrategy (), setFont (),和 QFont::setStyleStrategy ().
若 underline is true, sets the text format's font to be underlined; otherwise it is displayed non-underlined.
另請參閱 fontUnderline () 和 setFont ().
Sets the text format's font weight to weight .
另請參閱 fontWeight (), setFont (),和 QFont::Weight .
Sets the word spacing of this format to the given spacing (以像素為單位)。
該函數在 Qt 4.4 引入。
另請參閱 fontWordSpacing ().
Sets the pen used to draw the outlines of characters to the given pen .
另請參閱 textOutline ().
Sets the tool tip for a fragment of text to the given text .
該函數在 Qt 4.3 引入。
另請參閱 toolTip ().
Sets the underline color used for the characters with this format to the color 指定。
另請參閱 underlineColor ().
將文本的下劃綫樣式設為 style .
該函數在 Qt 4.2 引入。
另請參閱 underlineStyle ().
Sets the vertical alignment used for the characters with this format to the alignment 指定。
另請參閱 verticalAlignment ().
Returns the pen used to draw the outlines of characters in this format.
另請參閱 setTextOutline ().
Returns the tool tip that is displayed for a fragment of text.
該函數在 Qt 4.3 引入。
另請參閱 setToolTip ().
Returns the color used to underline the characters with this format.
另請參閱 setUnderlineColor ().
返迴文本的下劃綫樣式。
該函數在 Qt 4.2 引入。
另請參閱 setUnderlineStyle ().
Returns the vertical alignment used for characters with this format.
另請參閱 setVerticalAlignment ().