
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQTextFormat class provides formatting information for aQTextDocument.More...
| Header: | #include <QTextFormat> |
| Inherited By: | QTextBlockFormat,QTextCharFormat,QTextFrameFormat, andQTextListFormat |
Note: All functions in this class arereentrant.
| enum | FormatType { InvalidFormat, BlockFormat, CharFormat, ListFormat, ..., UserFormat } |
| enum | ObjectTypes { NoObject, ImageObject, TableObject, TableCellObject, UserObject } |
| enum | PageBreakFlag { PageBreak_Auto, PageBreak_AlwaysBefore, PageBreak_AlwaysAfter } |
| flags | PageBreakFlags |
| enum | Property { ObjectIndex, CssFloat, LayoutDirection, OutlinePen, ..., UserProperty } |
| QTextFormat() | |
| QTextFormat(int type) | |
| QTextFormat(const QTextFormat & other) | |
| ~QTextFormat() | |
| QBrush | background() const |
| bool | boolProperty(int propertyId) const |
| QBrush | brushProperty(int propertyId) const |
| void | clearBackground() |
| void | clearForeground() |
| void | clearProperty(int propertyId) |
| QColor | colorProperty(int propertyId) const |
| qreal | doubleProperty(int propertyId) const |
| QBrush | foreground() const |
| bool | hasProperty(int propertyId) const |
| int | intProperty(int propertyId) const |
| bool | isBlockFormat() const |
| bool | isCharFormat() const |
| bool | isFrameFormat() const |
| bool | isImageFormat() const |
| bool | isListFormat() const |
| bool | isTableCellFormat() const |
| bool | isTableFormat() const |
| bool | isValid() const |
| Qt::LayoutDirection | layoutDirection() const |
| QTextLength | lengthProperty(int propertyId) const |
| QVector<QTextLength> | lengthVectorProperty(int propertyId) const |
| void | merge(const QTextFormat & other) |
| int | objectIndex() const |
| int | objectType() const |
| QPen | penProperty(int propertyId) const |
| QMap<int, QVariant> | properties() const |
| QVariant | property(int propertyId) const |
| int | propertyCount() const |
| void | setBackground(const QBrush & brush) |
| void | setForeground(const QBrush & brush) |
| void | setLayoutDirection(Qt::LayoutDirection direction) |
| void | setObjectIndex(int index) |
| void | setObjectType(int type) |
| void | setProperty(int propertyId, const QVariant & value) |
| void | setProperty(int propertyId, const QVector<QTextLength> & value) |
| QString | stringProperty(int propertyId) const |
| QTextBlockFormat | toBlockFormat() const |
| QTextCharFormat | toCharFormat() const |
| QTextFrameFormat | toFrameFormat() const |
| QTextImageFormat | toImageFormat() const |
| QTextListFormat | toListFormat() const |
| QTextTableCellFormat | toTableCellFormat() const |
| QTextTableFormat | toTableFormat() const |
| int | type() const |
| operator QVariant() const | |
| bool | operator!=(const QTextFormat & other) const |
| QTextFormat & | operator=(const QTextFormat & other) |
| bool | operator==(const QTextFormat & other) const |
TheQTextFormat class provides formatting information for aQTextDocument.
AQTextFormat is a generic class used for describing the format of parts of aQTextDocument. The derived classesQTextCharFormat,QTextBlockFormat,QTextListFormat, andQTextTableFormat are usually more useful, and describe the formatting that is applied to specific parts of the document.
A format has aFormatType 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 bytype(), and the format can be tested withisCharFormat(),isBlockFormat(),isListFormat(),isTableFormat(),isFrameFormat(), andisImageFormat(). If the type is determined, it can be retrieved withtoCharFormat(),toBlockFormat(),toListFormat(),toTableFormat(),toFrameFormat(), andtoImageFormat().
A format's properties can be set with thesetProperty() functions, and retrieved withboolProperty(),intProperty(),doubleProperty(), andstringProperty() as appropriate. All the property IDs used in the format can be retrieved with allPropertyIds(). One format can be merged into another usingmerge().
A format's object index can be set withsetObjectIndex(), and retrieved withobjectIndex(). These methods can be used to associate the format with aQTextObject. It is used to represent lists, frames, and tables inside the document.
See alsoRich Text Processing.
This enum describes the text item aQTextFormat object is formatting.
| Constant | Value | Description |
|---|---|---|
QTextFormat::InvalidFormat | -1 | An invalid format as created by the default constructor |
QTextFormat::BlockFormat | 1 | The object formats a text block |
QTextFormat::CharFormat | 2 | The object formats a single character |
QTextFormat::ListFormat | 3 | The object formats a list |
QTextFormat::TableFormat | 4 | The object formats a table |
QTextFormat::FrameFormat | 5 | The object formats a frame |
QTextFormat::UserFormat | 100 |
See alsoQTextCharFormat,QTextBlockFormat,QTextListFormat,QTextTableFormat, andtype().
This enum describes what kind ofQTextObject this format is associated with.
| Constant | Value | Description |
|---|---|---|
QTextFormat::NoObject | 0 | |
QTextFormat::ImageObject | 1 | |
QTextFormat::TableObject | 2 | |
QTextFormat::TableCellObject | 3 | |
QTextFormat::UserObject | 0x1000 | The first object that can be used for application-specific purposes. |
See alsoQTextObject,QTextTable, andQTextObject::format().
This enum describes how page breaking is performed when printing. It maps to the corresponding css properties.
| Constant | Value | Description |
|---|---|---|
QTextFormat::PageBreak_Auto | 0 | The page break is determined automatically depending on the available space on the current page |
QTextFormat::PageBreak_AlwaysBefore | 0x001 | The page is always broken before the paragraph/table |
QTextFormat::PageBreak_AlwaysAfter | 0x010 | A new page is always started after the paragraph/table |
This enum was introduced or modified in Qt 4.2.
The PageBreakFlags type is a typedef forQFlags<PageBreakFlag>. It stores an OR combination of PageBreakFlag values.
See alsoQTextBlockFormat::pageBreakPolicy(),QTextFrameFormat::pageBreakPolicy(), andPageBreakPolicy.
This enum describes the different properties a format can have.
| Constant | Value | Description |
|---|---|---|
QTextFormat::ObjectIndex | 0x0 | The index of the formatted object. SeeobjectIndex(). |
Paragraph and character properties
| Constant | Value | Description |
|---|---|---|
QTextFormat::CssFloat | 0x0800 | How a frame is located relative to the surrounding text |
QTextFormat::LayoutDirection | 0x0801 | The layout direction of the text in the document (Qt::LayoutDirection). |
QTextFormat::OutlinePen | 0x810 | |
QTextFormat::ForegroundBrush | 0x821 | |
QTextFormat::BackgroundBrush | 0x820 | |
QTextFormat::BackgroundImageUrl | 0x823 |
Paragraph properties
| Constant | Value | Description |
|---|---|---|
QTextFormat::BlockAlignment | 0x1010 | |
QTextFormat::BlockTopMargin | 0x1030 | |
QTextFormat::BlockBottomMargin | 0x1031 | |
QTextFormat::BlockLeftMargin | 0x1032 | |
QTextFormat::BlockRightMargin | 0x1033 | |
QTextFormat::TextIndent | 0x1034 | |
QTextFormat::TabPositions | 0x1035 | Specifies the tab positions. The tab positions are structs ofQTextOption::Tab which are stored in aQList (internally, in aQList<QVariant>). |
QTextFormat::BlockIndent | 0x1040 | |
QTextFormat::LineHeight | 0x1048 | |
QTextFormat::LineHeightType | 0x1049 | |
QTextFormat::BlockNonBreakableLines | 0x1050 | |
QTextFormat::BlockTrailingHorizontalRulerWidth | 0x1060 | The width of a horizontal ruler element. |
Character properties
| Constant | Value | Description |
|---|---|---|
QTextFormat::FontFamily | 0x2000 | |
QTextFormat::FontPointSize | 0x2001 | |
QTextFormat::FontPixelSize | 0x2009 | |
QTextFormat::FontSizeAdjustment | 0x2002 | Specifies the change in size given to the fontsize already set using FontPointSize or FontPixelSize. |
QTextFormat::FontFixedPitch | 0x2008 | |
QTextFormat::FontWeight | 0x2003 | |
QTextFormat::FontItalic | 0x2004 | |
QTextFormat::FontUnderline | 0x2005 | This property has been deprecated. Use QTextFormat::TextUnderlineStyle instead. |
QTextFormat::FontOverline | 0x2006 | |
QTextFormat::FontStrikeOut | 0x2007 | |
QTextFormat::FontCapitalization | FirstFontProperty | Specifies the capitalization type that is to be applied to the text. |
QTextFormat::FontLetterSpacing | 0x1FE1 | Changes the default spacing between individual letters in the font. The value is specified in percentage, with 100 as the default value. |
QTextFormat::FontWordSpacing | 0x1FE2 | Changes the default spacing between individual words. A positive value increases the word spacing by the corresponding pixels; a negative value decreases the spacing. |
QTextFormat::FontStyleHint | 0x1FE3 | Corresponds to theQFont::StyleHint property |
QTextFormat::FontStyleStrategy | 0x1FE4 | Corresponds to theQFont::StyleStrategy property |
QTextFormat::FontKerning | 0x1FE5 | Specifies whether the font has kerning turned on. |
QTextFormat::FontHintingPreference | 0x1FE6 | Controls the use of hinting according to values of theQFont::HintingPreference enum. |
QTextFormat::TextUnderlineColor | 0x2010 | |
QTextFormat::TextVerticalAlignment | 0x2021 | |
QTextFormat::TextOutline | 0x2022 | |
QTextFormat::TextUnderlineStyle | 0x2023 | |
QTextFormat::TextToolTip | 0x2024 | Specifies the (optional) tool tip to be displayed for a fragment of text. |
QTextFormat::IsAnchor | 0x2030 | |
QTextFormat::AnchorHref | 0x2031 | |
QTextFormat::AnchorName | 0x2032 | |
QTextFormat::ObjectType | 0x2f00 |
List properties
| Constant | Value | Description |
|---|---|---|
QTextFormat::ListStyle | 0x3000 | Specifies the style used for the items in a list, described by values of theQTextListFormat::Style enum. |
QTextFormat::ListIndent | 0x3001 | Specifies the amount of indentation used for a list. |
QTextFormat::ListNumberPrefix | 0x3002 | Defines the text which is prepended to item numbers in numeric lists. |
QTextFormat::ListNumberSuffix | 0x3003 | Defines the text which is appended to item numbers in numeric lists. |
Table and frame properties
| Constant | Value | Description |
|---|---|---|
QTextFormat::FrameBorder | 0x4000 | |
QTextFormat::FrameBorderBrush | 0x4009 | |
QTextFormat::FrameBorderStyle | 0x4010 | See theBorderStyle enum. |
QTextFormat::FrameBottomMargin | 0x4006 | |
QTextFormat::FrameHeight | 0x4004 | |
QTextFormat::FrameLeftMargin | 0x4007 | |
QTextFormat::FrameMargin | 0x4001 | |
QTextFormat::FramePadding | 0x4002 | |
QTextFormat::FrameRightMargin | 0x4008 | |
QTextFormat::FrameTopMargin | 0x4005 | |
QTextFormat::FrameWidth | 0x4003 | |
QTextFormat::TableCellSpacing | 0x4102 | |
QTextFormat::TableCellPadding | 0x4103 | |
QTextFormat::TableColumns | 0x4100 | |
QTextFormat::TableColumnWidthConstraints | 0x4101 | |
QTextFormat::TableHeaderRowCount | 0x4104 |
Table cell properties
| Constant | Value |
|---|---|
QTextFormat::TableCellRowSpan | 0x4810 |
QTextFormat::TableCellColumnSpan | 0x4811 |
QTextFormat::TableCellLeftPadding | 0x4814 |
QTextFormat::TableCellRightPadding | 0x4815 |
QTextFormat::TableCellTopPadding | 0x4812 |
QTextFormat::TableCellBottomPadding | 0x4813 |
Image properties
| Constant | Value |
|---|---|
QTextFormat::ImageName | 0x5000 |
QTextFormat::ImageWidth | 0x5010 |
QTextFormat::ImageHeight | 0x5011 |
Selection properties
| Constant | Value | Description |
|---|---|---|
QTextFormat::FullWidthSelection | 0x06000 | When set on the characterFormat of a selection, the whole width of the text will be shown selected. |
Page break properties
| Constant | Value | Description |
|---|---|---|
QTextFormat::PageBreakPolicy | 0x7000 | Specifies how pages are broken. See thePageBreakFlag enum. |
QTextFormat::UserProperty | 0x100000 |
See alsoproperty() andsetProperty().
Creates a new text format with anInvalidFormat.
See alsoFormatType.
Creates a new text format of the giventype.
See alsoFormatType.
Creates a new text format with the same attributes as theother text format.
Destroys this text format.
Returns the brush used to paint the document's background.
See alsosetBackground(),clearBackground(), andforeground().
Returns the value of the property specified bypropertyId. If the property isn't of QTextFormat::Bool type, false is returned instead.
See alsosetProperty(),intProperty(),doubleProperty(),stringProperty(),colorProperty(),lengthProperty(),lengthVectorProperty(), andProperty.
Returns the value of the property given bypropertyId; if the property isn't ofQVariant::Brush type,Qt::NoBrush is returned instead.
See alsosetProperty(),boolProperty(),intProperty(),doubleProperty(),stringProperty(),lengthProperty(),lengthVectorProperty(), andProperty.
Clears the brush used to paint the document's background. The default brush will be used.
See alsobackground(),setBackground(), andclearForeground().
Clears the brush used to paint the document's foreground. The default brush will be used.
See alsoforeground(),setForeground(), andclearBackground().
Clears the value of the property given bypropertyId
See alsoProperty.
Returns the value of the property given bypropertyId; if the property isn't ofQVariant::Color type, an invalid color is returned instead.
See alsosetProperty(),boolProperty(),intProperty(),doubleProperty(),stringProperty(),lengthProperty(),lengthVectorProperty(), andProperty.
Returns the value of the property specified bypropertyId. If the property isn't ofQVariant::Double orQMetaType::Float type, 0 is returned instead.
See alsosetProperty(),boolProperty(),intProperty(),stringProperty(),colorProperty(),lengthProperty(),lengthVectorProperty(), andProperty.
Returns the brush used to render foreground details, such as text, frame outlines, and table borders.
See alsosetForeground(),clearForeground(), andbackground().
Returns true if the text format has a property with the givenpropertyId; otherwise returns false.
See alsoproperties() andProperty.
Returns the value of the property specified bypropertyId. If the property is not of QTextFormat::Integer type, 0 is returned instead.
See alsosetProperty(),boolProperty(),doubleProperty(),stringProperty(),colorProperty(),lengthProperty(),lengthVectorProperty(), andProperty.
Returns true if this text format is aBlockFormat; otherwise returns false.
Returns true if this text format is aCharFormat; otherwise returns false.
Returns true if this text format is aFrameFormat; otherwise returns false.
Returns true if this text format is an image format; otherwise returns false.
Returns true if this text format is aListFormat; otherwise returns false.
Returns true if this text format is aTableCellFormat; otherwise returns false.
This function was introduced in Qt 4.4.
Returns true if this text format is aTableFormat; otherwise returns false.
Returns true if the format is valid (i.e. is notInvalidFormat); otherwise returns false.
Returns the document's layout direction.
See alsosetLayoutDirection().
Returns the value of the property given bypropertyId.
See alsosetProperty(),boolProperty(),intProperty(),doubleProperty(),stringProperty(),colorProperty(),lengthVectorProperty(), andProperty.
Returns the value of the property given bypropertyId. If the property isn't of QTextFormat::LengthVector type, an empty length vector is returned instead.
See alsosetProperty(),boolProperty(),intProperty(),doubleProperty(),stringProperty(),colorProperty(),lengthProperty(), andProperty.
Merges theother format with this format; where there are conflicts theother format takes precedence.
Returns the index of the format object, or -1 if the format object is invalid.
See alsosetObjectIndex().
Returns the text format's object type.
See alsoObjectTypes andsetObjectType().
Returns the value of the property given bypropertyId; if the property isn't ofQVariant::Pen type,Qt::NoPen is returned instead.
See alsosetProperty(),boolProperty(),intProperty(),doubleProperty(),stringProperty(),lengthProperty(),lengthVectorProperty(), andProperty.
Returns a map with all properties of this text format.
Returns the property specified by the givenpropertyId.
See alsosetProperty() andProperty.
Returns the number of properties stored in the format.
This function was introduced in Qt 4.3.
Sets the brush use to paint the document's background to thebrush specified.
See alsobackground(),clearBackground(), andsetForeground().
Sets the foreground brush to the specifiedbrush. The foreground brush is mostly used to render text.
See alsoforeground(),clearForeground(), andsetBackground().
Sets the document's layout direction to the specifieddirection.
See alsolayoutDirection().
Sets the format object's objectindex.
See alsoobjectIndex().
Sets the text format's object type totype.
See alsoObjectTypes andobjectType().
Sets the property specified by thepropertyId to the givenvalue.
See alsoproperty() andProperty.
Sets the value of the property given bypropertyId tovalue.
See alsolengthVectorProperty() andProperty.
Returns the value of the property given bypropertyId; if the property isn't ofQVariant::String type, an empty string is returned instead.
See alsosetProperty(),boolProperty(),intProperty(),doubleProperty(),colorProperty(),lengthProperty(),lengthVectorProperty(), andProperty.
Returns this format as a block format.
Returns this format as a character format.
Returns this format as a frame format.
Returns this format as an image format.
Returns this format as a list format.
Returns this format as a table cell format.
This function was introduced in Qt 4.4.
Returns this format as a table format.
Returns the type of this format.
See alsoFormatType.
Returns the text format as aQVariant
Returns true if this text format is different from theother text format.
Assigns theother text format to this text format, and returns a reference to this text format.
Returns true if this text format is the same as theother text format.
© 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.