QtBase
v6.3.1
|
The QTextFormat class provides formatting information for a QTextDocument. \inmodule QtGui. More...
#include <qtextformat.h>
Friends | |
class | QTextFormatCollection |
class | QTextCharFormat |
Q_GUI_EXPORT QDataStream & | operator<< (QDataStream &, const QTextFormat &) |
Q_GUI_EXPORT QDataStream & | operator>> (QDataStream &, QTextFormat &) |
The QTextFormat class provides formatting information for a QTextDocument. \inmodule QtGui.
\reentrant
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 125 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 129 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 296 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 306 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. \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 \value TextOutline \value TextUnderlineStyle \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.
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
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 140 of file qtextformat.h.
QTextFormat::QTextFormat | ( | ) |
Creates a new text format with an InvalidFormat
.
Definition at line 904 of file qtextformat.cpp.
|
explicit |
Creates a new text format of the given type.
Definition at line 914 of file qtextformat.cpp.
QTextFormat::QTextFormat | ( | const QTextFormat & | other | ) |
Creates a new text format with the same attributes as the other text format.
Definition at line 926 of file qtextformat.cpp.
QTextFormat::~QTextFormat | ( | ) |
Destroys this text format.
Definition at line 955 of file qtextformat.cpp.
|
inline |
Returns the brush used to paint the document's background.
Definition at line 386 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 1070 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 1180 of file qtextformat.cpp.
|
inline |
Clears the brush used to paint the document's background. The default brush will be used.
Definition at line 388 of file qtextformat.h.
|
inline |
Clears the brush used to paint the document's foreground. The default brush will be used.
Definition at line 395 of file qtextformat.h.
void QTextFormat::clearProperty | ( | int | propertyId | ) |
Clears the value of the property given by propertyId
Definition at line 1276 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 1144 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 1108 of file qtextformat.cpp.
|
inline |
Returns the brush used to render foreground details, such as text, frame outlines, and table borders.
Definition at line 393 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 1343 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 1087 of file qtextformat.cpp.
|
inline |
Returns true
if this text format is a BlockFormat
; otherwise returns false
.
Definition at line 360 of file qtextformat.h.
|
inline |
Returns true
if this text format is a CharFormat
; otherwise returns false
.
Definition at line 359 of file qtextformat.h.
|
inline |
Returns true if the format does not store any properties; false otherwise.
Definition at line 328 of file qtextformat.h.
|
inline |
Returns true
if this text format is a FrameFormat
; otherwise returns false
.
Definition at line 362 of file qtextformat.h.
|
inline |
Returns true
if this text format is an image format; otherwise returns false
.
Definition at line 363 of file qtextformat.h.
|
inline |
Returns true
if this text format is a ListFormat
; otherwise returns false
.
Definition at line 361 of file qtextformat.h.
|
inline |
Returns true
if this text format is a TableCellFormat
; otherwise returns false
.
Definition at line 365 of file qtextformat.h.
|
inline |
Returns true
if this text format is a TableFormat
; otherwise returns false
.
Definition at line 364 of file qtextformat.h.
|
inline |
Returns true
if the format is valid (i.e. is not InvalidFormat); otherwise returns false
.
Definition at line 327 of file qtextformat.h.
|
inline |
Returns the document's layout direction.
Definition at line 381 of file qtextformat.h.
QTextLength QTextFormat::lengthProperty | ( | int | propertyId | ) | const |
Returns the value of the property given by propertyId.
Definition at line 1196 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 1211 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 972 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 1307 of file qtextformat.cpp.
|
inline |
Returns the text format's object type.
Definition at line 356 of file qtextformat.h.
QTextFormat::operator QVariant | ( | ) | const |
Returns the text format as a QVariant
Definition at line 963 of file qtextformat.cpp.
|
inline |
Returns true
if this text format is different from the other text format.
Definition at line 376 of file qtextformat.h.
QTextFormat & QTextFormat::operator= | ( | const QTextFormat & | other | ) |
Assigns the other text format to this text format, and returns a reference to this text format.
Definition at line 937 of file qtextformat.cpp.
bool QTextFormat::operator== | ( | const QTextFormat & | other | ) | const |
Returns true
if this text format is the same as the other text format.
Definition at line 1390 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 1162 of file qtextformat.cpp.
Returns a map with all properties of this text format.
Definition at line 1357 of file qtextformat.cpp.
QVariant QTextFormat::property | ( | int | propertyId | ) | const |
Returns the property specified by the given propertyId.
Definition at line 1234 of file qtextformat.cpp.
int QTextFormat::propertyCount | ( | ) | const |
Definition at line 1371 of file qtextformat.cpp.
Sets the brush use to paint the document's background to the brush specified.
Definition at line 384 of file qtextformat.h.
Sets the foreground brush to the specified brush. The foreground brush is mostly used to render text.
Definition at line 391 of file qtextformat.h.
|
inline |
Sets the document's layout direction to the specified direction.
Definition at line 379 of file qtextformat.h.
void QTextFormat::setObjectIndex | ( | int | index | ) |
Sets the format object's object index.
Definition at line 1324 of file qtextformat.cpp.
|
inline |
Sets the text format's object type to type.
Definition at line 410 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 1259 of file qtextformat.cpp.
Sets the property specified by the propertyId to the given value.
Definition at line 1244 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 1126 of file qtextformat.cpp.
|
inline |
Swaps this text format with other. This function is very fast and never fails.
Definition at line 322 of file qtextformat.h.
QTextBlockFormat QTextFormat::toBlockFormat | ( | ) | const |
Returns this format as a block format.
Definition at line 1008 of file qtextformat.cpp.
QTextCharFormat QTextFormat::toCharFormat | ( | ) | const |
Returns this format as a character format.
Definition at line 1016 of file qtextformat.cpp.
QTextFrameFormat QTextFormat::toFrameFormat | ( | ) | const |
Returns this format as a frame format.
Definition at line 1040 of file qtextformat.cpp.
QTextImageFormat QTextFormat::toImageFormat | ( | ) | const |
Returns this format as an image format.
Definition at line 1048 of file qtextformat.cpp.
QTextListFormat QTextFormat::toListFormat | ( | ) | const |
Returns this format as a list format.
Definition at line 1024 of file qtextformat.cpp.
QTextTableCellFormat QTextFormat::toTableCellFormat | ( | ) | const |
Returns this format as a table cell format.
Definition at line 1058 of file qtextformat.cpp.
QTextTableFormat QTextFormat::toTableFormat | ( | ) | const |
Returns this format as a table format.
Definition at line 1032 of file qtextformat.cpp.
int QTextFormat::type | ( | ) | const |
Returns the type of this format.
Definition at line 1000 of file qtextformat.cpp.
|
friend |
Definition at line 440 of file qtextformat.cpp.
|
friend |
Definition at line 473 of file qtextformat.cpp.
|
friend |
Definition at line 403 of file qtextformat.h.
|
friend |
Definition at line 402 of file qtextformat.h.