QTextFormat Class
The QTextFormat class provides formatting information for a QTextDocument. More…
| Header | #include <QTextFormat> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Gui) |
| Module | Nt GUI C++ Classes |
| Inherited by | QTextBlockFormat, QTextCharFormat, QTextListFormat |
List of all members, including inherited members
Public Types
| enum | FormatType |
| enum | Property |
Public Functions
| QTextFormat() | |
| QTextFormat(int type) | |
| void | merge(const QTextFormat &other) |
| bool | isValid() const |
| bool | isEmpty() const |
| int | type() const |
| bool | boolProperty(int propertyId) const |
| int | intProperty(int propertyId) const |
| qreal | doubleProperty(int propertyId) const |
| QString | stringProperty(int propertyId) const |
| QBrush | brushProperty(int propertyId) const |
| QVariant | property(int propertyId) const |
| void | setProperty(int propertyId, const QVariant &value) |
| void | clearProperty(int propertyId) |
| bool | hasProperty(int propertyId) const |
| int | propertyCount() const |
| QMap<int, QVariant> | properties() const |
| bool | isCharFormat() const |
| bool | isBlockFormat() const |
| bool | isListFormat() const |
| QTextBlockFormat | toBlockFormat() const |
| QTextCharFormat | toCharFormat() const |
| QTextListFormat | toListFormat() const |
| void | setBackground(const QBrush &brush) |
| QBrush | background() const |
| void | clearBackground() |
| void | setForeground(const QBrush &brush) |
| QBrush | foreground() const |
| void | clearForeground() |
| bool | operator==(const QTextFormat &other) const |
| bool | operator!=(const QTextFormat &other) const |
Detailed Description
A format is a set of properties, each of them a number from Property with a value. A property that is not set is left to whatever the format is applied on top of: merge() adds the properties of another format to this one. The subclasses have functions for the properties that go with characters (QTextCharFormat), paragraphs (QTextBlockFormat) and lists (QTextListFormat).
See also QTextCharFormat, QTextBlockFormat and QTextDocument.
Differences from Qt
Only the properties of Property are known, and a format is one of the three kinds named here: there are no frame, table, image or table cell formats, no object index, no pen properties and no colorProperty() or lengthProperty(). Formats are plain values that are not shared.
Member Type Documentation
enum QTextFormat::FormatType
The kinds of formats.
| Constant | Description |
|---|---|
QTextFormat::InvalidFormat | A format that was default-constructed. |
QTextFormat::BlockFormat | The format of a paragraph; see QTextBlockFormat. |
QTextFormat::CharFormat | The format of characters; see QTextCharFormat. |
QTextFormat::ListFormat | The format of a list; see QTextListFormat. |
QTextFormat::UserFormat | The first number for formats of an application. |
enum QTextFormat::Property
The properties that a format can have, by the numbers that Qt gives them. Nt has the ones listed here.
| Constant | Description |
|---|---|
QTextFormat::BackgroundBrush | The brush behind the text. |
QTextFormat::ForegroundBrush | The brush that the text is drawn with. |
QTextFormat::BlockAlignment | The alignment of a paragraph. |
QTextFormat::BlockTopMargin | The space above a paragraph, in pixels. |
QTextFormat::BlockBottomMargin | The space below a paragraph. |
QTextFormat::BlockLeftMargin | The space left of a paragraph. |
QTextFormat::BlockRightMargin | The space right of a paragraph. |
QTextFormat::TextIndent | The indentation of the first line of a paragraph. |
QTextFormat::BlockIndent | The number of steps that a paragraph is indented by. |
QTextFormat::HeadingLevel | The level of a heading, 1 to 6; 0 for a paragraph that is none. |
QTextFormat::FontFamilies | The families of the font, in order of preference. |
QTextFormat::FontPointSize | The size of the font in points. |
QTextFormat::FontWeight | The weight of the font. |
QTextFormat::FontItalic | Whether the font is italic. |
QTextFormat::FontUnderline | Whether the text is underlined. |
QTextFormat::FontStrikeOut | Whether the text is struck out. |
QTextFormat::FontFixedPitch | Whether the font has a fixed pitch. |
QTextFormat::IsAnchor | Whether the text is a link. |
QTextFormat::AnchorHref | The target of the link. |
QTextFormat::ListStyle | The style of a list; see QTextListFormat::Style. |
QTextFormat::ListIndent | The number of steps that a list is indented by. |
QTextFormat::UserProperty | The first number for properties of an application. |
Member Function Documentation
QTextFormat::QTextFormat()
Constructs an invalid format, of the type InvalidFormat.
QTextFormat::QTextFormat(int type)
Constructs a format of the type type, one of FormatType, without properties.
QBrush QTextFormat::background() const
Returns the brush behind the text; its style is Qt::NoBrush if none is set.
bool QTextFormat::boolProperty(int propertyId) const
Returns the value of the property propertyId as a bool, or false if it is not set.
QBrush QTextFormat::brushProperty(int propertyId) const
Returns the value of the property propertyId as a brush, or a brush of the style Qt::NoBrush if it is not set.
void QTextFormat::clearBackground()
Takes the background brush away.
void QTextFormat::clearForeground()
Takes the foreground brush away.
void QTextFormat::clearProperty(int propertyId)
Removes the property propertyId from the format.
qreal QTextFormat::doubleProperty(int propertyId) const
Returns the value of the property propertyId as a number, or 0 if it is not set.
QBrush QTextFormat::foreground() const
Returns the brush that the text is drawn with; its style is Qt::NoBrush if none is set, and the text then has the color of its surroundings.
bool QTextFormat::hasProperty(int propertyId) const
Returns true if the property propertyId is set; otherwise returns false.
int QTextFormat::intProperty(int propertyId) const
Returns the value of the property propertyId as an int, or 0 if it is not set.
bool QTextFormat::isBlockFormat() const
Returns true if this is the format of a block.
bool QTextFormat::isCharFormat() const
Returns true if this is the format of characters.
bool QTextFormat::isEmpty() const
Returns true if the format has no properties.
bool QTextFormat::isListFormat() const
Returns true if this is the format of a list.
bool QTextFormat::isValid() const
Returns true if the format has a type; a default-constructed one has none.
void QTextFormat::merge(const QTextFormat &other)
Adds the properties of other to this format. A property that both have gets the value that it has in other.
bool QTextFormat::operator!=(const QTextFormat &other) const
Returns true if this format differs from other; otherwise returns false.
bool QTextFormat::operator==(const QTextFormat &other) const
Returns true if this format has the same type and the same properties with the same values as other; otherwise returns false.
QMap<int, QVariant> QTextFormat::properties() const
Returns the properties that are set, with their values.
QVariant QTextFormat::property(int propertyId) const
Returns the value of the property propertyId, or an invalid QVariant if it is not set.
See also setProperty() and hasProperty().
int QTextFormat::propertyCount() const
Returns the number of properties that are set.
void QTextFormat::setBackground(const QBrush &brush)
Sets the brush behind the text to brush.
See also background() and clearBackground().
void QTextFormat::setForeground(const QBrush &brush)
Sets the brush that the text is drawn with to brush.
See also foreground() and clearForeground().
void QTextFormat::setProperty(int propertyId, const QVariant &value)
Sets the property propertyId to value. An invalid value clears the property.
See also property() and clearProperty().
QString QTextFormat::stringProperty(int propertyId) const
Returns the value of the property propertyId as a string, or an empty string if it is not set.
QTextBlockFormat QTextFormat::toBlockFormat() const
Returns the format as a QTextBlockFormat, with its properties, or an empty block format if it is not the format of a block.
QTextCharFormat QTextFormat::toCharFormat() const
Returns the format as a QTextCharFormat, with its properties, or an empty character format if it is not the format of characters.
QTextListFormat QTextFormat::toListFormat() const
Returns the format as a QTextListFormat, with its properties, or an empty list format if it is not the format of a list.
int QTextFormat::type() const
Returns the type of the format, one of FormatType.