QTextFormat露
- PyQt5.QtGui.QTextFormat
Inherited by QTextBlockFormat, QTextCharFormat, QTextFrameFormat, QTextListFormat.
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 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鈥檚 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鈥檚 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
Classes露
Enums露
- FormatType
This enum describes the text item a QTextFormat object is formatting.
See also
QTextCharFormat, QTextBlockFormat, QTextListFormat, QTextTableFormat, type().
Member
Value
Description
BlockFormat 1
The object formats a text block
CharFormat 2
The object formats a single character
FrameFormat 5
The object formats a frame
InvalidFormat -1
An invalid format as created by the default constructor
ListFormat 3
The object formats a list
TableFormat TODO
TODO
UserFormat TODO
TODO
- ObjectTypes
This enum describes what kind of QTextObject this format is associated with.
See also
Member
Value
Description
ImageObject TODO
TODO
NoObject TODO
TODO
TableCellObject TODO
TODO
TableObject TODO
TODO
UserObject 0x1000
The first object that can be used for application-specific purposes.
- PageBreakFlag
This enum describes how page breaking is performed when printing. It maps to the corresponding css properties.
See also
Member
Value
Description
PageBreak_AlwaysAfter 0x010
A new page is always started after the paragraph/table
PageBreak_AlwaysBefore 0x001
The page is always broken before the paragraph/table
PageBreak_Auto 0
The page break is determined automatically depending on the available space on the current page
- Property
This enum describes the different properties a format can have.
Paragraph and character properties
Paragraph properties
Character properties
List properties
Table and frame properties
Table cell properties
Image properties
Selection properties
Page break properties
See also
Member
Value
Description
AnchorHref TODO
TODO
AnchorName TODO
TODO
BackgroundBrush TODO
TODO
BackgroundImageUrl TODO
TODO
BlockAlignment TODO
TODO
BlockBottomMargin TODO
TODO
BlockCodeFence TODO
TODO
BlockCodeLanguage TODO
TODO
BlockIndent TODO
TODO
BlockLeftMargin TODO
TODO
BlockMarker TODO
TODO
BlockNonBreakableLines TODO
TODO
BlockQuoteLevel TODO
TODO
BlockRightMargin TODO
TODO
BlockTopMargin TODO
TODO
BlockTrailingHorizontalRulerWidth 0x1060
The width of a horizontal ruler element.
CssFloat 0x0800
How a frame is located relative to the surrounding text
FirstFontProperty TODO
TODO
FontCapitalization FirstFontProperty
Specifies the capitalization type that is to be applied to the text.
FontFamilies TODO
TODO
FontFamily TODO
TODO
FontFixedPitch TODO
TODO
FontHintingPreference 0x1FE6
Controls the use of hinting according to values of the HintingPreference enum.
FontItalic TODO
TODO
FontKerning 0x1FE5
Specifies whether the font has kerning turned on.
FontLetterSpacing 0x1FE1
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%.
FontLetterSpacingType TODO
Specifies the meaning of the property. The default is PercentageSpacing.
FontOverline TODO
TODO
FontPixelSize TODO
TODO
FontPointSize TODO
TODO
FontSizeAdjustment 0x2002
Specifies the change in size given to the fontsize already set using or .
FontSizeIncrement TODO
TODO
FontStretch TODO
Corresponds to the Stretch property
FontStrikeOut TODO
TODO
FontStyleHint 0x1FE3
Corresponds to the StyleHint property
FontStyleName TODO
TODO
FontStyleStrategy 0x1FE4
Corresponds to the StyleStrategy property
FontUnderline 0x2005
This property has been deprecated. Use instead.
FontWeight TODO
TODO
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.
ForegroundBrush TODO
TODO
FrameBorder TODO
TODO
FrameBorderBrush TODO
TODO
FrameBorderStyle 0x4010
See the BorderStyle enum.
FrameBottomMargin TODO
TODO
FrameHeight TODO
TODO
FrameLeftMargin TODO
TODO
FrameMargin TODO
TODO
FramePadding TODO
TODO
FrameRightMargin TODO
TODO
FrameTopMargin TODO
TODO
FrameWidth TODO
TODO
FullWidthSelection 0x06000
When set on the characterFormat of a selection, the whole width of the text will be shown selected.
HeadingLevel TODO
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.
ImageAltText TODO
TODO
ImageHeight TODO
TODO
ImageName TODO
TODO
ImageQuality TODO
TODO
ImageTitle TODO
TODO
ImageWidth TODO
TODO
IsAnchor TODO
TODO
LastFontProperty TODO
TODO
LayoutDirection 0x0801
The layout direction of the text in the document (LayoutDirection).
LineHeight TODO
TODO
LineHeightType TODO
TODO
ListIndent 0x3001
Specifies the amount of indentation used for a list.
ListNumberPrefix 0x3002
Defines the text which is prepended to item numbers in numeric lists.
ListNumberSuffix 0x3003
Defines the text which is appended to item numbers in numeric lists.
ListStyle 0x3000
Specifies the style used for the items in a list, described by values of the Style enum.
ObjectIndex 0x0
The index of the formatted object. See objectIndex().
ObjectType TODO
TODO
OutlinePen TODO
TODO
PageBreakPolicy 0x7000
Specifies how pages are broken. See the PageBreakFlag enum.
TableBorderCollapse TODO
TODO
TableCellBottomBorder TODO
TODO
TableCellBottomBorderBrush TODO
TODO
TableCellBottomBorderStyle TODO
TODO
TableCellBottomPadding TODO
TODO
TableCellColumnSpan TODO
TODO
TableCellLeftBorder TODO
TODO
TableCellLeftBorderBrush TODO
TODO
TableCellLeftBorderStyle TODO
TODO
TableCellLeftPadding TODO
TODO
TableCellPadding TODO
TODO
TableCellRightBorder TODO
TODO
TableCellRightBorderBrush TODO
TODO
TableCellRightBorderStyle TODO
TODO
TableCellRightPadding TODO
TODO
TableCellRowSpan TODO
TODO
TableCellSpacing TODO
TODO
TableCellTopBorder TODO
TODO
TableCellTopBorderBrush TODO
TODO
TableCellTopBorderStyle TODO
TODO
TableCellTopPadding TODO
TODO
TableColumns TODO
TODO
TableColumnWidthConstraints TODO
TODO
TableHeaderRowCount TODO
TODO
TabPositions 0x1035
Specifies the tab positions. The tab positions are structs of Tab which are stored in a QList (internally, in a QList<QVariant>).
TextIndent TODO
TODO
TextOutline TODO
TODO
TextToolTip 0x2024
Specifies the (optional) tool tip to be displayed for a fragment of text.
TextUnderlineColor TODO
TODO
TextUnderlineStyle TODO
TODO
TextVerticalAlignment TODO
TODO
UserProperty TODO
TODO
Methods露
- __init__()
Creates a new text format with an
InvalidFormat
.See also
FormatType.
- __init__(int)
Creates a new text format of the given type.
See also
FormatType.
- __init__(QTextFormat)
TODO
- __init__(Any)
TODO
- background() → QBrush
See also
- boolProperty(int) → bool
Returns the value of the property specified by propertyId. If the property isn鈥檛 of QTextFormat::Bool type, false is returned instead.
See also
setProperty(), intProperty(), doubleProperty(), stringProperty(), colorProperty(), lengthProperty(), lengthVectorProperty(), Property.
- brushProperty(int) → QBrush
Returns the value of the property given by propertyId; if the property isn鈥檛 of Brush type, NoBrush is returned instead.
See also
setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(), lengthProperty(), lengthVectorProperty(), Property.
- clearBackground()
TODO
- clearForeground()
TODO
- clearProperty(int)
Clears the value of the property given by propertyId
See also
Property.
- colorProperty(int) → QColor
Returns the value of the property given by propertyId; if the property isn鈥檛 of Color type, an invalid color is returned instead.
See also
setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(), lengthProperty(), lengthVectorProperty(), Property.
- doubleProperty(int) → float
Returns the value of the property specified by propertyId. If the property isn鈥檛 of Double or Float type, 0 is returned instead.
See also
setProperty(), boolProperty(), intProperty(), stringProperty(), colorProperty(), lengthProperty(), lengthVectorProperty(), Property.
- __eq__(QTextFormat) → bool
TODO
- foreground() → QBrush
See also
- hasProperty(int) → bool
Returns
true
if the text format has a property with the given propertyId; otherwise returnsfalse
.See also
properties(), Property.
- intProperty(int) → int
Returns the value of the property specified by propertyId. If the property is not of QTextFormat::Integer type, 0 is returned instead.
See also
setProperty(), boolProperty(), doubleProperty(), stringProperty(), colorProperty(), lengthProperty(), lengthVectorProperty(), Property.
- isBlockFormat() → bool
TODO
- isCharFormat() → bool
TODO
- isEmpty() → bool
TODO
- isFrameFormat() → bool
TODO
- isImageFormat() → bool
TODO
- isListFormat() → bool
TODO
- isTableCellFormat() → bool
TODO
- isTableFormat() → bool
TODO
- isValid() → bool
TODO
- layoutDirection() → LayoutDirection
See also
- lengthProperty(int) → QTextLength
Returns the value of the property given by propertyId.
See also
setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(), colorProperty(), lengthVectorProperty(), Property.
- lengthVectorProperty(int) → List[QTextLength]
Returns the value of the property given by propertyId. If the property isn鈥檛 of QTextFormat::LengthVector type, an empty length vector is returned instead.
See also
setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(), colorProperty(), lengthProperty(), Property.
- merge(QTextFormat)
Merges the other format with this format; where there are conflicts the other format takes precedence.
- __ne__(QTextFormat) → bool
TODO
- objectIndex() → int
Returns the index of the format object, or -1 if the format object is invalid.
See also
- objectType() → int
See also
- penProperty(int) → QPen
Returns the value of the property given by propertyId; if the property isn鈥檛 of Pen type, NoPen is returned instead.
See also
setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(), lengthProperty(), lengthVectorProperty(), Property.
- properties() → Dict[int, Any]
Returns a map with all properties of this text format.
- property(int) → Any
Returns the property specified by the given propertyId.
See also
setProperty(), Property.
- propertyCount() → int
Returns the number of properties stored in the format.
- setBackground(Union[QBrush, QColor, GlobalColor, QGradient])
See also
- setForeground(Union[QBrush, QColor, GlobalColor, QGradient])
See also
- setLayoutDirection(LayoutDirection)
See also
- setObjectIndex(int)
See also
- setObjectType(int)
See also
- setProperty(int, Any)
Sets the property specified by the propertyId to the given value.
See also
property(), Property.
- setProperty(int, Iterable[QTextLength])
Sets the value of the property given by propertyId to value.
See also
lengthVectorProperty(), Property.
- stringProperty(int) → str
Returns the value of the property given by propertyId; if the property isn鈥檛 of String type, an empty string is returned instead.
See also
setProperty(), boolProperty(), intProperty(), doubleProperty(), colorProperty(), lengthProperty(), lengthVectorProperty(), Property.
- swap(QTextFormat)
TODO
- toBlockFormat() → QTextBlockFormat
Returns this format as a block format.
- toCharFormat() → QTextCharFormat
Returns this format as a character format.
- toFrameFormat() → QTextFrameFormat
Returns this format as a frame format.
- toImageFormat() → QTextImageFormat
Returns this format as an image format.
- toListFormat() → QTextListFormat
Returns this format as a list format.
- toTableCellFormat() → QTextTableCellFormat
Returns this format as a table cell format.
- toTableFormat() → QTextTableFormat
Returns this format as a table format.
- type() → int
Returns the type of this format.
See also
FormatType.