Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QTextFormat Class Reference

The QTextFormat class provides formatting information for a QTextDocument. More...

    #include <QTextFormat>

Inherited by QTextCharFormat, QTextBlockFormat, QTextListFormat, and QTextFrameFormat.

- List of all members, including inherited members

### Public Types

- enum FormatType { InvalidFormat, BlockFormat, CharFormat, ListFormat, TableFormat, ..., UserFormat }
- enum ObjectTypes { NoObject, ImageObject, TableObject }
- enum Property { ObjectIndex, CssFloat, BlockDirection, BlockAlignment, BlockTopMargin, ..., UserProperty }
- enum PropertyType { Undefined, Bool, Color, Integer, Float, ..., LengthVector }

### Public Functions

- QTextFormat ()
- QTextFormat ( int type )
- QTextFormat ( const QTextFormat & other )
- ~QTextFormat ()
- QList<int> allPropertyIds () const
- bool boolProperty ( int propertyId, bool defaultValue = false ) const
- void clearProperty ( int propertyId )
- QColor colorProperty ( int propertyId, const QColor & defaultValue = QColor() ) const
- float floatProperty ( int propertyId, float defaultValue = 0.0 ) const
- bool hasProperty ( int propertyId ) const
- int intProperty ( int propertyId, int defaultValue = 0 ) const
- bool isBlockFormat () const
- bool isCharFormat () const
- bool isFrameFormat () const
- bool isImageFormat () const
- bool isListFormat () const
- bool isTableFormat () const
- bool isValid () const
- QTextLength lengthProperty ( int propertyId ) const
- QVector<QTextLength> lengthVectorProperty ( int propertyId ) const
- void merge ( const QTextFormat & other )
- int objectIndex () const
- int objectType () const
- PropertyType propertyType ( int propertyId ) const
- void setObjectIndex ( int index )
- void setObjectType ( int type )
- void setProperty ( int propertyId, const QString & value )
- void setProperty ( int propertyId, const QColor & value )
- void setProperty ( int propertyId, const QTextLength & value )
- void setProperty ( int propertyId, const QVector<QTextLength> & value )
- void setProperty ( int propertyId, const QString & value, const QString & defaultValue )
- void setProperty ( int propertyId, const QColor & value, const QColor & defaultValue )
- void setProperty ( int propertyId, bool value )
- void setProperty ( int propertyId, int value )
- void setProperty ( int propertyId, float value )
- void setProperty ( int propertyId, bool value, bool defaultValue )
- void setProperty ( int propertyId, int value, int defaultValue )
- void setProperty ( int propertyId, float value, float defaultValue )
- QString stringProperty ( int propertyId, const QString & defaultValue = QString::null ) const
- QTextBlockFormat toBlockFormat () const
- QTextCharFormat toCharFormat () const
- QTextFrameFormat toFrameFormat () const
- QTextImageFormat toImageFormat () const
- QTextListFormat toListFormat () const
- QTextTableFormat toTableFormat () const
- int type () const
- bool operator!= ( const QTextFormat & other ) const
- QTextFormat & operator= ( const QTextFormat & other )
- bool operator== ( const QTextFormat & other ) const

## Detailed Description

The QTextFormat class provides formatting information for a QTextDocument.

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 thing 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 `PropertyType`.

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(), floatProperty(), 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.

See also l{text.html}{Text Related Classes}.

## Member Type Documentation

### enum QTextFormat::FormatType

`QTextFormat::InvalidFormat` |
`QTextFormat::BlockFormat` |
`QTextFormat::CharFormat` |
`QTextFormat::ListFormat` |
`QTextFormat::TableFormat` |
`QTextFormat::FrameFormat` |

`QTextFormat::UserFormat` |

### enum QTextFormat::ObjectTypes

`QTextFormat::NoObject` |
`QTextFormat::ImageObject` |
`QTextFormat::TableObject` |

### enum QTextFormat::Property

`QTextFormat::ObjectIndex` |

Paragraph and character properties

`QTextFormat::CssFloat` |

Paragraph properties

`QTextFormat::BlockDirection` |
`QTextFormat::BlockAlignment` |
`QTextFormat::BlockTopMargin` |
`QTextFormat::BlockBottomMargin` |
`QTextFormat::BlockLeftMargin` |
`QTextFormat::BlockRightMargin` |
`QTextFormat::BlockFirstLineMargin` |
`QTextFormat::BlockIndent` |
`QTextFormat::BlockNonBreakableLines` |
`QTextFormat::BlockBackgroundColor` |

Character properties

`QTextFormat::FontFamily` |
`QTextFormat::FontPointSize` |
`QTextFormat::FontSizeIncrement` |
`QTextFormat::FontWeight` |
`QTextFormat::FontItalic` |
`QTextFormat::FontUnderline` |
`QTextFormat::FontOverline` |
`QTextFormat::FontStrikeOut` |
`QTextFormat::FontFixedPitch` |

`QTextFormat::TextColor` |

`QTextFormat::IsAnchor` |
`QTextFormat::AnchorHref` |
`QTextFormat::AnchorName` |

`QTextFormat::ObjectType` |

List properties

`QTextFormat::ListStyle` |
`QTextFormat::ListIndent` |

Table and frame properties

`QTextFormat::TableColumns` |
`QTextFormat::FrameBorder` |
`QTextFormat::FrameMargin` |
`QTextFormat::FramePadding` |
`QTextFormat::Width` |
`QTextFormat::Height` |
`QTextFormat::TableColumnWidthConstraints` |
`QTextFormat::TableCellSpacing` |
`QTextFormat::TableCellPadding` |
`QTextFormat::TableBackgroundColor` |

Table cell properties

`QTextFormat::TableCellRowSpan` |
`QTextFormat::TableCellColumnSpan` |
`QTextFormat::TableCellBackgroundColor` |

Image properties

`QTextFormat::ImageName` |
`QTextFormat::ImageWidth` |
`QTextFormat::ImageHeight` |

`QTextFormat::UserProperty` |

### enum QTextFormat::PropertyType

`QTextFormat::Undefined` |
`QTextFormat::Bool` |
`QTextFormat::Color` |
`QTextFormat::Integer` |
`QTextFormat::Float` |
`QTextFormat::String` |
`QTextFormat::FormatObject` |
`QTextFormat::Length` |
`QTextFormat::LengthVector` |

## Member Function Documentation

### QTextFormat::QTextFormat ()

Creates a new text format with an `InvalidFormat`.

See also FormatType.

### QTextFormat::QTextFormat ( int type )

Creates a new text format of the given type.

See also FormatType.

### QTextFormat::QTextFormat ( const QTextFormat & other )

Creates a new text format with the same attributes at the other text format.

### QTextFormat::~QTextFormat ()

Destroys this text format.

### QList<int> QTextFormat::allPropertyIds () const

Returns a list of all the property IDs for this text format.

See also hasProperty(), propertyType(), and PropertyType.

### bool QTextFormat::boolProperty ( int propertyId, bool defaultValue = false ) const

Returns the value of the property specified by propertyId. If the property isn't of `QTextFormat::Bool` type, the defaultValue is returned instead.

See also setProperty(), intProperty(), floatProperty(), stringProperty(), colorProperty(), lengthProperty(), lengthVectorProperty(), and PropertyType.

### void QTextFormat::clearProperty ( int propertyId )

Clears the value of the property given by propertyId

### QColor QTextFormat::colorProperty ( int propertyId, const QColor & defaultValue = QColor() ) const

Returns the value of the property given by propertyId; if the property isn't of `QTextFormat::Color` type the defaultValue is returned instead.

See also setProperty(), boolProperty(), intProperty(), floatProperty(), stringProperty(), lengthProperty(), lengthVectorProperty(), and PropertyType.

### float QTextFormat::floatProperty ( int propertyId, float defaultValue = 0.0 ) const

Returns the value of the property specified by propertyId. If the property isn't of `QTextFormat::Float` type, the defaultValue is returned instead.

See also setProperty(), boolProperty(), intProperty(), stringProperty(), colorProperty(), lengthProperty(), lengthVectorProperty(), and PropertyType.

### bool QTextFormat::hasProperty ( int propertyId ) const

Returns true if the text format has a property with the given propertyId; otherwise returns false.

See also propertyType(), allPropertyIds(), and PropertyType.

### int QTextFormat::intProperty ( int propertyId, int defaultValue = 0 ) const

Returns the value of the property specified by propertyId. If the property is not of `QTextFormat::Integer` type, the defaultValue is returned instead.

See also setProperty(), boolProperty(), floatProperty(), stringProperty(), colorProperty(), lengthProperty(), lengthVectorProperty(), and PropertyType.

### bool QTextFormat::isBlockFormat () const

Returns true if this text format is a `BlockFormat`; otherwise returns false.

### bool QTextFormat::isCharFormat () const

Returns true if this text format is a `CharFormat`; otherwise returns false.

### bool QTextFormat::isFrameFormat () const

Returns true if this text format is a `FrameFormat`; otherwise returns false.

### bool QTextFormat::isImageFormat () const

Returns true if this text format is an image format; otherwise returns false.

### bool QTextFormat::isListFormat () const

Returns true if this text format is a `ListFormat`; otherwise returns false.

### bool QTextFormat::isTableFormat () const

Returns true if this text format is a `TableFormat`; otherwise returns false.

### bool QTextFormat::isValid () const

Returns true if the format is valid (i.e. is not `InvalidFormat`); otherwise returns false.

### QTextLength QTextFormat::lengthProperty ( int propertyId ) const

Returns the value of the property given by propertyId; if the property isn't of `QTextFormat::Length` type an variable length is returned instead.

See also setProperty(), boolProperty(), intProperty(), floatProperty(), stringProperty(), colorProperty(), lengthVectorProperty(), and PropertyType.

### QVector<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 length vector is returned instead.

See also setProperty(), boolProperty(), intProperty(), floatProperty(), stringProperty(), colorProperty(), lengthProperty(), and PropertyType.

### void QTextFormat::merge ( const QTextFormat & other )

Merges the other format with this format; where there are conflicts the other format takes precedence.

### int QTextFormat::objectIndex () const

Returns the index of the format object, or -1 if the format object is invalid.

See also setObjectIndex().

### int QTextFormat::objectType () const

Returns the text format's object type. See `ObjectTypes`.

### PropertyType QTextFormat::propertyType ( int propertyId ) const

Returns the property type for the given propertyId.

See also hasProperty(), allPropertyIds(), and PropertyType.

### void QTextFormat::setObjectIndex ( int index )

Sets the format object's object index.

See also objectIndex().

### void QTextFormat::setObjectType ( int type )

Sets the text format's object type. See `ObjectTypes`.

### void QTextFormat::setProperty ( int propertyId, const QString & value )

Sets the value of the property given by propertyId to value.

See also stringProperty() and PropertyType.

### void QTextFormat::setProperty ( int propertyId, const QColor & value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the value of the property given by propertyId to value.

See also colorProperty() and PropertyType.

### void QTextFormat::setProperty ( int propertyId, const QTextLength & value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the value of the property given by propertyId to value.

See also lengthProperty() and PropertyType.

### void QTextFormat::setProperty ( int propertyId, const QVector<QTextLength> & value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the value of the property given by propertyId to value.

See also lengthVectorProperty() and PropertyType.

### void QTextFormat::setProperty ( int propertyId, const QString & value, const QString & defaultValue )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the value of the property given by propertyId to value, unless value == defaultValue, in which case the property's value is cleared.

See also stringProperty() and PropertyType.

### void QTextFormat::setProperty ( int propertyId, const QColor & value, const QColor & defaultValue )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the value of the property given by propertyId to value, unless value == defaultValue, in which case the property's value is cleared.

See also colorProperty() and PropertyType.

### void QTextFormat::setProperty ( int propertyId, bool value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the value of the property given by propertyId to value.

See also boolProperty() and PropertyType.

### void QTextFormat::setProperty ( int propertyId, int value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the value of the property given by propertyId to value.

See also intProperty() and PropertyType.

### void QTextFormat::setProperty ( int propertyId, float value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the value of the property given by propertyId to value.

See also floatProperty() and PropertyType.

### void QTextFormat::setProperty ( int propertyId, bool value, bool defaultValue )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the value of the property given by propertyId to value, unless value == defaultValue, in which case the property's value is cleared.

See also intProperty() and PropertyType.

### void QTextFormat::setProperty ( int propertyId, int value, int defaultValue )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the value of the property given by propertyId to value, unless value == defaultValue, in which case the property's value is cleared.

See also intProperty() and PropertyType.

### void QTextFormat::setProperty ( int propertyId, float value, float defaultValue )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the value of the property given by propertyId to value, unless value == defaultValue, in which case the property's value is cleared.

See also floatProperty() and PropertyType.

### QString QTextFormat::stringProperty ( int propertyId, const QString & defaultValue = QString::null ) const

Returns the value of the property given by propertyId; if the property isn't of `QTextFormat::String` type the defaultValue is returned instead.

See also setProperty(), boolProperty(), intProperty(), floatProperty(), colorProperty(), lengthProperty(), lengthVectorProperty(), and PropertyType.

### QTextBlockFormat QTextFormat::toBlockFormat () const

Returns this format as a block format.

### QTextCharFormat QTextFormat::toCharFormat () const

Returns this format as a character format.

### QTextFrameFormat QTextFormat::toFrameFormat () const

Returns this format as a frame format.

### QTextImageFormat QTextFormat::toImageFormat () const

Returns this format as an image format.

### QTextListFormat QTextFormat::toListFormat () const

Returns this format as a list format.

### QTextTableFormat QTextFormat::toTableFormat () const

Returns this format as a table format.

### int QTextFormat::type () const

Returns the type of this format.

See also ObjectTypes.

### bool QTextFormat::operator!= ( const QTextFormat & other ) const

Returns true if this text format is different from the other text format.

### QTextFormat & QTextFormat::operator= ( const QTextFormat & other )

Assigns the other text format to this text format, and returns a reference to this text format.

### bool QTextFormat::operator== ( const QTextFormat & other ) const

Returns true if this text format is the same as the other text format.