![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\reentrant More...
#include <qtextformat.h>
Public Member Functions | |
QTextFormat () | |
Creates a new text format with an InvalidFormat . | |
QTextFormat (int type) | |
Creates a new text format of the given type. | |
QTextFormat (const QTextFormat &rhs) | |
Creates a new text format with the same attributes as the other text format. | |
QTextFormat & | operator= (const QTextFormat &rhs) |
Assigns the other text format to this text format, and returns a reference to this text format. | |
~QTextFormat () | |
Destroys this text format. | |
void | swap (QTextFormat &other) |
void | merge (const QTextFormat &other) |
Merges the other format with this format; where there are conflicts the other format takes precedence. | |
bool | isValid () const |
Returns true if the format is valid (i.e. | |
bool | isEmpty () const |
int | type () const |
Returns the type of this format. | |
int | objectIndex () const |
Returns the index of the format object, or -1 if the format object is invalid. | |
void | setObjectIndex (int object) |
Sets the format object's object index. | |
QVariant | property (int propertyId) const |
Returns the property specified by the given propertyId. | |
void | setProperty (int propertyId, const QVariant &value) |
Sets the property specified by the propertyId to the given value. | |
void | clearProperty (int propertyId) |
Clears the value of the property given by propertyId. | |
bool | hasProperty (int propertyId) const |
Returns true if the text format has a property with the given propertyId; otherwise returns false . | |
bool | boolProperty (int propertyId) const |
Returns the value of the property specified by propertyId. | |
int | intProperty (int propertyId) const |
Returns the value of the property specified by propertyId. | |
qreal | doubleProperty (int propertyId) const |
Returns the value of the property specified by propertyId. | |
QString | stringProperty (int propertyId) const |
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QString type, an empty string is returned instead. | |
QColor | colorProperty (int propertyId) const |
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QColor type, an invalid color is returned instead. | |
QPen | penProperty (int propertyId) const |
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QPen type, Qt::NoPen is returned instead. | |
QBrush | brushProperty (int propertyId) const |
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QBrush type, Qt::NoBrush is returned instead. | |
QTextLength | lengthProperty (int propertyId) const |
Returns the value of the property given by propertyId. | |
QList< QTextLength > | lengthVectorProperty (int propertyId) const |
Returns the value of the property given by propertyId. | |
void | setProperty (int propertyId, const QList< QTextLength > &lengths) |
Sets the value of the property given by propertyId to value. | |
QMap< int, QVariant > | properties () const |
Returns a map with all properties of this text format. | |
int | propertyCount () const |
void | setObjectType (int type) |
Sets the text format's object type to type. | |
int | objectType () const |
Returns the text format's object type. | |
bool | isCharFormat () const |
Returns true if this text format is a CharFormat ; otherwise returns false . | |
bool | isBlockFormat () const |
Returns true if this text format is a BlockFormat ; otherwise returns false . | |
bool | isListFormat () const |
Returns true if this text format is a ListFormat ; otherwise returns false . | |
bool | isFrameFormat () const |
Returns true if this text format is a FrameFormat ; otherwise returns false . | |
bool | isImageFormat () const |
Returns true if this text format is an image format; otherwise returns false . | |
bool | isTableFormat () const |
Returns true if this text format is a TableFormat ; otherwise returns false . | |
bool | isTableCellFormat () const |
QTextBlockFormat | toBlockFormat () const |
Returns this format as a block format. | |
QTextCharFormat | toCharFormat () const |
Returns this format as a character format. | |
QTextListFormat | toListFormat () const |
Returns this format as a list format. | |
QTextTableFormat | toTableFormat () const |
Returns this format as a table format. | |
QTextFrameFormat | toFrameFormat () const |
Returns this format as a frame format. | |
QTextImageFormat | toImageFormat () const |
Returns this format as an image format. | |
QTextTableCellFormat | toTableCellFormat () const |
bool | operator== (const QTextFormat &rhs) const |
Returns true if this text format is the same as the other text format. | |
bool | operator!= (const QTextFormat &rhs) const |
Returns true if this text format is different from the other text format. | |
operator QVariant () const | |
Returns the text format as a QVariant. | |
void | setLayoutDirection (Qt::LayoutDirection direction) |
Sets the document's layout direction to the specified direction. | |
Qt::LayoutDirection | layoutDirection () const |
Returns the document's layout direction. | |
void | setBackground (const QBrush &brush) |
Sets the brush use to paint the document's background to the brush specified. | |
QBrush | background () const |
Returns the brush used to paint the document's background. | |
void | clearBackground () |
Clears the brush used to paint the document's background. | |
void | setForeground (const QBrush &brush) |
Sets the foreground brush to the specified brush. | |
QBrush | foreground () const |
Returns the brush used to render foreground details, such as text, frame outlines, and table borders. | |
void | clearForeground () |
Clears the brush used to paint the document's foreground. | |
Friends | |
class | QTextFormatCollection |
class | QTextCharFormat |
Q_GUI_EXPORT QDataStream & | operator<< (QDataStream &stream, const QTextFormat &fmt) |
Q_GUI_EXPORT QDataStream & | operator>> (QDataStream &stream, QTextFormat &fmt) |
\reentrant
The QTextFormat class provides formatting information for a QTextDocument. \inmodule QtGui
A QTextFormat is a generic class used for describing the format of parts of a QTextDocument. The derived classes QTextCharFormat, QTextBlockFormat, QTextListFormat, and QTextTableFormat are usually more useful, and describe the formatting that is applied to specific parts of the document.
A format has a FormatType
which specifies the kinds of text item it can format; e.g. a block of text, a list, a table, etc. A format also has various properties (some specific to particular format types), as described by the Property enum. Every property has a corresponding Property.
The format type is given by type(), and the format can be tested with isCharFormat(), isBlockFormat(), isListFormat(), isTableFormat(), isFrameFormat(), and isImageFormat(). If the type is determined, it can be retrieved with toCharFormat(), toBlockFormat(), toListFormat(), toTableFormat(), toFrameFormat(), and toImageFormat().
A format's properties can be set with the setProperty() functions, and retrieved with boolProperty(), intProperty(), doubleProperty(), and stringProperty() as appropriate. All the property IDs used in the format can be retrieved with allPropertyIds(). One format can be merged into another using merge().
A format's object index can be set with setObjectIndex(), and retrieved with objectIndex(). These methods can be used to associate the format with a QTextObject. It is used to represent lists, frames, and tables inside the document.
Definition at line 89 of file qtextformat.h.
This enum describes the text item a QTextFormat object is formatting.
\value InvalidFormat An invalid format as created by the default constructor \value BlockFormat The object formats a text block \value CharFormat The object formats a single character \value ListFormat The object formats a list \value FrameFormat The object formats a frame
\value UserFormat
Enumerator | |
---|---|
InvalidFormat | |
BlockFormat | |
CharFormat | |
ListFormat | |
FrameFormat | |
UserFormat |
Definition at line 93 of file qtextformat.h.
This enum describes what kind of QTextObject this format is associated with.
\value NoObject \value ImageObject \value TableObject \value TableCellObject \value UserObject The first object that can be used for application-specific purposes.
Enumerator | |
---|---|
NoObject | |
ImageObject | |
TableObject | |
TableCellObject | |
UserObject |
Definition at line 263 of file qtextformat.h.
This enum describes how page breaking is performed when printing. It maps to the corresponding css properties.
\value PageBreak_Auto The page break is determined automatically depending on the available space on the current page \value PageBreak_AlwaysBefore The page is always broken before the paragraph/table \value PageBreak_AlwaysAfter A new page is always started after the paragraph/table
Enumerator | |
---|---|
PageBreak_Auto | |
PageBreak_AlwaysBefore | |
PageBreak_AlwaysAfter |
Definition at line 273 of file qtextformat.h.
This enum describes the different properties a format can have.
\value ObjectIndex The index of the formatted object. See objectIndex().
Paragraph and character properties
\value CssFloat How a frame is located relative to the surrounding text \value LayoutDirection The layout direction of the text in the document (Qt::LayoutDirection).
\value OutlinePen \value ForegroundBrush \value BackgroundBrush \value BackgroundImageUrl
Paragraph properties
\value BlockAlignment \value BlockTopMargin \value BlockBottomMargin \value BlockLeftMargin \value BlockRightMargin \value TextIndent \value TabPositions Specifies the tab positions. The tab positions are structs of QTextOption::Tab which are stored in a QList (internally, in a QList<QVariant>). \value BlockIndent \value LineHeight \value LineHeightType \value BlockNonBreakableLines \value BlockTrailingHorizontalRulerWidth The width of a horizontal ruler element. \value HeadingLevel The level of a heading, for example 1 corresponds to an HTML H1 tag; otherwise 0. This enum value has been added in Qt 5.12. \value BlockCodeFence The character that was used in the "fences" around a Markdown code block. If the code block was indented rather than fenced, the block should not have this property. This enum value has been added in Qt 5.14.
\value BlockQuoteLevel The depth of nested quoting on this block: 1 means the block is a top-level block quote. Blocks that are not block quotes should not have this property. This enum value has been added in Qt 5.14. \value BlockCodeLanguage The programming language in a preformatted or code block. Blocks that do not contain code should not have this property. This enum value has been added in Qt 5.14. \value BlockMarker The \l{QTextBlockFormat::MarkerType}{type of adornment} to be shown alongside the block. This enum value has been added in Qt 5.14.
Character properties
\value FontFamily e{This property has been deprecated.} Use QTextFormat::FontFamilies instead. \omitvalue OldFontFamily \value FontFamilies \value FontStyleName \value FontPointSize \value FontPixelSize \value FontSizeAdjustment Specifies the change in size given to the fontsize already set using FontPointSize or FontPixelSize. \value FontFixedPitch \omitvalue FontSizeIncrement \value FontWeight \value FontItalic \value FontUnderline {This property has been deprecated.} Use QTextFormat::TextUnderlineStyle instead. \value FontOverline \value FontStrikeOut \value FontCapitalization Specifies the capitalization type that is to be applied to the text. \value FontLetterSpacingType Specifies the meaning of the FontLetterSpacing property. The default is QFont::PercentageSpacing. \value FontLetterSpacing Changes the default spacing between individual letters in the font. The value is specified as a percentage or absolute value, depending on FontLetterSpacingType. The default value is 100%. \value FontWordSpacing Changes the default spacing between individual words. A positive value increases the word spacing by the corresponding pixels; a negative value decreases the spacing. \value FontStretch Corresponds to the QFont::Stretch property \value FontStyleHint Corresponds to the QFont::StyleHint property \value FontStyleStrategy Corresponds to the QFont::StyleStrategy property \value FontKerning Specifies whether the font has kerning turned on. \value FontHintingPreference Controls the use of hinting according to values of the QFont::HintingPreference enum.
\omitvalue FirstFontProperty \omitvalue LastFontProperty
\value TextUnderlineColor Specifies the color to draw underlines, overlines and strikeouts. \value TextVerticalAlignment Specifies the type of text vertical alignment according to the values of the QTextCharFormat::VerticalAlignment enum. \value TextOutline Specifies a \l QPen used to draw the text outline. \value TextUnderlineStyle Specifies the style of text underline according to the values of the QTextCharFormat::UnderlineStyle enum. \value TextToolTip Specifies the (optional) tool tip to be displayed for a fragment of text. \value TextSuperScriptBaseline Specifies the baseline (in % of height) of superscript texts. \value TextSubScriptBaseline Specifies the baseline (in % of height) of subscript texts. \value TextBaselineOffset Specifies the baseline (in % of height) of text. A positive value moves up the text, by the corresponding %; a negative value moves it down.
\value IsAnchor \value AnchorHref \value AnchorName \omitvalue OldFontLetterSpacingType \omitvalue OldFontStretch \omitvalue OldTextUnderlineColor \value ObjectType
List properties
\value ListStyle Specifies the style used for the items in a list, described by values of the QTextListFormat::Style enum. \value ListIndent Specifies the amount of indentation used for a list. \value ListNumberPrefix Defines the text which is prepended to item numbers in numeric lists. \value ListNumberSuffix Defines the text which is appended to item numbers in numeric lists. \value [since 6.6] ListStart Defines the first value of a list.
Table and frame properties
\value FrameBorder \value FrameBorderBrush \value FrameBorderStyle See the \l{QTextFrameFormat::BorderStyle}{BorderStyle} enum. \value FrameBottomMargin \value FrameHeight \value FrameLeftMargin \value FrameMargin \value FramePadding \value FrameRightMargin \value FrameTopMargin \value FrameWidth \value TableCellSpacing \value TableCellPadding \value TableColumns \value TableColumnWidthConstraints \value TableHeaderRowCount \value TableBorderCollapse Specifies the \l QTextTableFormat::borderCollapse property.
Table cell properties
\value TableCellRowSpan \value TableCellColumnSpan \value TableCellLeftPadding \value TableCellRightPadding \value TableCellTopPadding \value TableCellBottomPadding
Table cell properties intended for use with \l QTextTableFormat::borderCollapse enabled
\value TableCellTopBorder \value TableCellBottomBorder \value TableCellLeftBorder \value TableCellRightBorder
\value TableCellTopBorderStyle \value TableCellBottomBorderStyle \value TableCellLeftBorderStyle \value TableCellRightBorderStyle
\value TableCellTopBorderBrush \value TableCellBottomBorderBrush \value TableCellLeftBorderBrush \value TableCellRightBorderBrush
Image properties
\value ImageName The filename or source of the image. \value ImageTitle The title attribute of an HTML image tag, or the quoted string that comes after the URL in a Markdown image link. This enum value has been added in Qt 5.14. \value ImageAltText The alt attribute of an HTML image tag, or the image description in a Markdown image link. This enum value has been added in Qt 5.14. \value ImageWidth \value ImageHeight \value ImageQuality \value ImageMaxWidth This enum value has been added in Qt 6.8.
Selection properties
\value FullWidthSelection When set on the characterFormat of a selection, the whole width of the text will be shown selected.
Page break properties
\value PageBreakPolicy Specifies how pages are broken. See the PageBreakFlag enum.
\value UserProperty
Definition at line 104 of file qtextformat.h.
QTextFormat::QTextFormat | ( | ) |
Creates a new text format with an InvalidFormat
.
Definition at line 874 of file qtextformat.cpp.
|
explicit |
Creates a new text format of the given type.
Definition at line 884 of file qtextformat.cpp.
QTextFormat::QTextFormat | ( | const QTextFormat & | rhs | ) |
Creates a new text format with the same attributes as the other text format.
Definition at line 896 of file qtextformat.cpp.
QTextFormat::~QTextFormat | ( | ) |
Destroys this text format.
Definition at line 923 of file qtextformat.cpp.
|
inline |
Returns the brush used to paint the document's background.
Definition at line 353 of file qtextformat.h.
bool QTextFormat::boolProperty | ( | int | propertyId | ) | const |
Returns the value of the property specified by propertyId.
If the property isn't of QTextFormat::Bool type, false is returned instead.
Definition at line 1042 of file qtextformat.cpp.
QBrush QTextFormat::brushProperty | ( | int | propertyId | ) | const |
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QBrush type, Qt::NoBrush is returned instead.
Definition at line 1152 of file qtextformat.cpp.
|
inline |
Clears the brush used to paint the document's background.
The default brush will be used.
Definition at line 355 of file qtextformat.h.
|
inline |
Clears the brush used to paint the document's foreground.
The default brush will be used.
Definition at line 362 of file qtextformat.h.
void QTextFormat::clearProperty | ( | int | propertyId | ) |
Clears the value of the property given by propertyId.
Definition at line 1246 of file qtextformat.cpp.
QColor QTextFormat::colorProperty | ( | int | propertyId | ) | const |
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QColor type, an invalid color is returned instead.
Definition at line 1116 of file qtextformat.cpp.
qreal QTextFormat::doubleProperty | ( | int | propertyId | ) | const |
Returns the value of the property specified by propertyId.
If the property isn't of QMetaType::Double or QMetaType::Float type, 0 is returned instead.
Definition at line 1080 of file qtextformat.cpp.
|
inline |
Returns the brush used to render foreground details, such as text, frame outlines, and table borders.
Definition at line 360 of file qtextformat.h.
bool QTextFormat::hasProperty | ( | int | propertyId | ) | const |
Returns true
if the text format has a property with the given propertyId; otherwise returns false
.
Definition at line 1313 of file qtextformat.cpp.
int QTextFormat::intProperty | ( | int | propertyId | ) | const |
Returns the value of the property specified by propertyId.
If the property is not of QTextFormat::Integer type, 0 is returned instead.
Definition at line 1059 of file qtextformat.cpp.
|
inline |
Returns true
if this text format is a BlockFormat
; otherwise returns false
.
Definition at line 327 of file qtextformat.h.
|
inline |
Returns true
if this text format is a CharFormat
; otherwise returns false
.
Definition at line 326 of file qtextformat.h.
|
inline |
Returns true if the format does not store any properties; false otherwise.
Definition at line 295 of file qtextformat.h.
|
inline |
Returns true
if this text format is a FrameFormat
; otherwise returns false
.
Definition at line 329 of file qtextformat.h.
|
inline |
Returns true
if this text format is an image format; otherwise returns false
.
Definition at line 330 of file qtextformat.h.
|
inline |
Returns true
if this text format is a ListFormat
; otherwise returns false
.
Definition at line 328 of file qtextformat.h.
|
inline |
Returns true
if this text format is a TableCellFormat
; otherwise returns false
.
Definition at line 332 of file qtextformat.h.
|
inline |
Returns true
if this text format is a TableFormat
; otherwise returns false
.
Definition at line 331 of file qtextformat.h.
|
inline |
Returns true
if the format is valid (i.e.
is not InvalidFormat); otherwise returns false
.
Definition at line 294 of file qtextformat.h.
|
inline |
Returns the document's layout direction.
Definition at line 348 of file qtextformat.h.
QTextLength QTextFormat::lengthProperty | ( | int | propertyId | ) | const |
Returns the value of the property given by propertyId.
Definition at line 1168 of file qtextformat.cpp.
QList< QTextLength > QTextFormat::lengthVectorProperty | ( | int | propertyId | ) | const |
Returns the value of the property given by propertyId.
If the property isn't of QTextFormat::LengthVector type, an empty list is returned instead.
Definition at line 1183 of file qtextformat.cpp.
void QTextFormat::merge | ( | const QTextFormat & | other | ) |
Merges the other format with this format; where there are conflicts the other format takes precedence.
Definition at line 940 of file qtextformat.cpp.
int QTextFormat::objectIndex | ( | ) | const |
Returns the index of the format object, or -1 if the format object is invalid.
Definition at line 1277 of file qtextformat.cpp.
|
inline |
Returns the text format's object type.
Definition at line 323 of file qtextformat.h.
QTextFormat::operator QVariant | ( | ) | const |
Returns the text format as a QVariant.
Definition at line 931 of file qtextformat.cpp.
|
inline |
Returns true
if this text format is different from the other text format.
Definition at line 343 of file qtextformat.h.
QTextFormat & QTextFormat::operator= | ( | const QTextFormat & | rhs | ) |
Assigns the other text format to this text format, and returns a reference to this text format.
Definition at line 907 of file qtextformat.cpp.
bool QTextFormat::operator== | ( | const QTextFormat & | rhs | ) | const |
Returns true
if this text format is the same as the other text format.
Definition at line 1360 of file qtextformat.cpp.
QPen QTextFormat::penProperty | ( | int | propertyId | ) | const |
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QPen type, Qt::NoPen is returned instead.
Definition at line 1134 of file qtextformat.cpp.
Returns a map with all properties of this text format.
Definition at line 1327 of file qtextformat.cpp.
QVariant QTextFormat::property | ( | int | propertyId | ) | const |
Returns the property specified by the given propertyId.
Definition at line 1206 of file qtextformat.cpp.
int QTextFormat::propertyCount | ( | ) | const |
Definition at line 1341 of file qtextformat.cpp.
Sets the brush use to paint the document's background to the brush specified.
Definition at line 351 of file qtextformat.h.
Sets the foreground brush to the specified brush.
The foreground brush is mostly used to render text.
Definition at line 358 of file qtextformat.h.
|
inline |
Sets the document's layout direction to the specified direction.
Definition at line 346 of file qtextformat.h.
void QTextFormat::setObjectIndex | ( | int | index | ) |
Sets the format object's object index.
Definition at line 1294 of file qtextformat.cpp.
|
inline |
Sets the text format's object type to type.
Definition at line 377 of file qtextformat.h.
void QTextFormat::setProperty | ( | int | propertyId, |
const QList< QTextLength > & | value ) |
Sets the value of the property given by propertyId to value.
Definition at line 1229 of file qtextformat.cpp.
Sets the property specified by the propertyId to the given value.
Definition at line 1216 of file qtextformat.cpp.
QString QTextFormat::stringProperty | ( | int | propertyId | ) | const |
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QString type, an empty string is returned instead.
Definition at line 1098 of file qtextformat.cpp.
|
inline |
Definition at line 289 of file qtextformat.h.
QTextBlockFormat QTextFormat::toBlockFormat | ( | ) | const |
Returns this format as a block format.
Definition at line 980 of file qtextformat.cpp.
QTextCharFormat QTextFormat::toCharFormat | ( | ) | const |
Returns this format as a character format.
Definition at line 988 of file qtextformat.cpp.
QTextFrameFormat QTextFormat::toFrameFormat | ( | ) | const |
Returns this format as a frame format.
Definition at line 1012 of file qtextformat.cpp.
QTextImageFormat QTextFormat::toImageFormat | ( | ) | const |
Returns this format as an image format.
Definition at line 1020 of file qtextformat.cpp.
QTextListFormat QTextFormat::toListFormat | ( | ) | const |
Returns this format as a list format.
Definition at line 996 of file qtextformat.cpp.
QTextTableCellFormat QTextFormat::toTableCellFormat | ( | ) | const |
Returns this format as a table cell format.
Definition at line 1030 of file qtextformat.cpp.
QTextTableFormat QTextFormat::toTableFormat | ( | ) | const |
Returns this format as a table format.
Definition at line 1004 of file qtextformat.cpp.
int QTextFormat::type | ( | ) | const |
|
friend |
Definition at line 404 of file qtextformat.cpp.
|
friend |
Definition at line 437 of file qtextformat.cpp.
|
friend |
Definition at line 370 of file qtextformat.h.
|
friend |
Definition at line 369 of file qtextformat.h.