6.0.0-rc4Source

QTextFormat Class

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

Header#include <QTextFormat>
CMaketarget_link_libraries(app PRIVATE Nt::Gui)
ModuleNt GUI C++ Classes
Inherited byQTextBlockFormat, QTextCharFormat, QTextListFormat

List of all members, including inherited members

Public Types

Public Functions

QTextFormat()
QTextFormat(int type)
voidmerge(const QTextFormat &other)
boolisValid() const
boolisEmpty() const
inttype() const
boolboolProperty(int propertyId) const
intintProperty(int propertyId) const
qrealdoubleProperty(int propertyId) const
QStringstringProperty(int propertyId) const
QBrushbrushProperty(int propertyId) const
QVariantproperty(int propertyId) const
voidsetProperty(int propertyId, const QVariant &value)
voidclearProperty(int propertyId)
boolhasProperty(int propertyId) const
intpropertyCount() const
QMap<int, QVariant>properties() const
boolisCharFormat() const
boolisBlockFormat() const
boolisListFormat() const
QTextBlockFormattoBlockFormat() const
QTextCharFormattoCharFormat() const
QTextListFormattoListFormat() const
voidsetBackground(const QBrush &brush)
QBrushbackground() const
voidclearBackground()
voidsetForeground(const QBrush &brush)
QBrushforeground() const
voidclearForeground()
booloperator==(const QTextFormat &other) const
booloperator!=(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.

ConstantDescription
QTextFormat::InvalidFormatA format that was default-constructed.
QTextFormat::BlockFormatThe format of a paragraph; see QTextBlockFormat.
QTextFormat::CharFormatThe format of characters; see QTextCharFormat.
QTextFormat::ListFormatThe format of a list; see QTextListFormat.
QTextFormat::UserFormatThe 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.

ConstantDescription
QTextFormat::BackgroundBrushThe brush behind the text.
QTextFormat::ForegroundBrushThe brush that the text is drawn with.
QTextFormat::BlockAlignmentThe alignment of a paragraph.
QTextFormat::BlockTopMarginThe space above a paragraph, in pixels.
QTextFormat::BlockBottomMarginThe space below a paragraph.
QTextFormat::BlockLeftMarginThe space left of a paragraph.
QTextFormat::BlockRightMarginThe space right of a paragraph.
QTextFormat::TextIndentThe indentation of the first line of a paragraph.
QTextFormat::BlockIndentThe number of steps that a paragraph is indented by.
QTextFormat::HeadingLevelThe level of a heading, 1 to 6; 0 for a paragraph that is none.
QTextFormat::FontFamiliesThe families of the font, in order of preference.
QTextFormat::FontPointSizeThe size of the font in points.
QTextFormat::FontWeightThe weight of the font.
QTextFormat::FontItalicWhether the font is italic.
QTextFormat::FontUnderlineWhether the text is underlined.
QTextFormat::FontStrikeOutWhether the text is struck out.
QTextFormat::FontFixedPitchWhether the font has a fixed pitch.
QTextFormat::IsAnchorWhether the text is a link.
QTextFormat::AnchorHrefThe target of the link.
QTextFormat::ListStyleThe style of a list; see QTextListFormat::Style.
QTextFormat::ListIndentThe number of steps that a list is indented by.
QTextFormat::UserPropertyThe first number for properties of an application.

Member Function Documentation

QTextFormat::QTextFormat()

Constructs an invalid format, of the type InvalidFormat.

[explicit] 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.