QTextFormatclass provides formatting information for aQTextDocument. 更多 …
继承者: QTextBlockFormat , QTextCharFormat , QTextFrameFormat , QTextImageFormat , QTextListFormat , QTextTableCellFormat , QTextTableFormat
def
__eq__
(rhs)
def
__ne__
(rhs)
def
background
()
def
boolProperty
(propertyId)
def
brushProperty
(propertyId)
def
clearBackground
()
def
clearForeground
()
def
clearProperty
(propertyId)
def
colorProperty
(propertyId)
def
doubleProperty
(propertyId)
def
foreground
()
def
hasProperty
(propertyId)
def
intProperty
(propertyId)
def
isBlockFormat
()
def
isCharFormat
()
def
isEmpty
()
def
isFrameFormat
()
def
isImageFormat
()
def
isListFormat
()
def
isTableCellFormat
()
def
isTableFormat
()
def
isValid
()
def
layoutDirection
()
def
lengthProperty
(propertyId)
def
lengthVectorProperty
(propertyId)
def
merge
(other)
def
objectIndex
()
def
objectType
()
def
penProperty
(propertyId)
def
properties
()
def
特性
(propertyId)
def
propertyCount
()
def
setBackground
(brush)
def
setForeground
(brush)
def
setLayoutDirection
(direction)
def
setObjectIndex
(object)
def
setObjectType
(type)
def
setProperty
(propertyId, lengths)
def
setProperty
(propertyId, value)
def
stringProperty
(propertyId)
def
swap
(other)
def
toBlockFormat
()
def
toCharFormat
()
def
toFrameFormat
()
def
toImageFormat
()
def
toListFormat
()
def
toTableCellFormat
()
def
toTableFormat
()
def
type
()
A
QTextFormatis a generic class used for describing the format of parts of aQTextDocument. The derived classesQTextCharFormat,QTextBlockFormat,QTextListFormat,和QTextTableFormatare usually more useful, and describe the formatting that is applied to specific parts of the document.A format has a
FormatTypewhich 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 withisCharFormat(),isBlockFormat(),isListFormat(),isTableFormat(),isFrameFormat(),和isImageFormat(). If the type is determined, it can be retrieved withtoCharFormat(),toBlockFormat(),toListFormat(),toTableFormat(),toFrameFormat(),和toImageFormat().A format’s properties can be set with the
setProperty()functions, and retrieved withboolProperty(),intProperty(),doubleProperty(),和stringProperty()as appropriate. All the property IDs used in the format can be retrieved with allPropertyIds(). One format can be merged into another usingmerge().A format’s object index can be set with
setObjectIndex(), and retrieved withobjectIndex(). These methods can be used to associate the format with aQTextObject. It is used to represent lists, frames, and tables inside the document.另请参阅
QTextFormat
¶
QTextFormat(rhs)
QTextFormat(type)
- param type
int- param rhs
Creates a new text format with an
InvalidFormat
.
另请参阅
FormatType
Creates a new text format of the given
type
.
另请参阅
FormatType
PySide2.QtGui.QTextFormat.
FormatType
¶
This enum describes the text item a
QTextFormat
object is formatting.
|
常量 |
描述 |
|---|---|
|
QTextFormat.InvalidFormat |
An invalid format as created by the default constructor |
|
QTextFormat.BlockFormat |
The object formats a text block |
|
QTextFormat.CharFormat |
The object formats a single character |
|
QTextFormat.ListFormat |
The object formats a list |
|
QTextFormat.FrameFormat |
The object formats a frame |
|
QTextFormat.UserFormat |
PySide2.QtGui.QTextFormat.
特性
¶
This enum describes the different properties a format can have.
|
常量 |
描述 |
|---|---|
|
QTextFormat.ObjectIndex |
The index of the formatted object. See
|
Paragraph and character properties
|
常量 |
描述 |
|---|---|
|
QTextFormat.CssFloat |
How a frame is located relative to the surrounding text |
|
QTextFormat.LayoutDirection |
The layout direction of the text in the document (
|
|
QTextFormat.OutlinePen |
|
|
QTextFormat.ForegroundBrush |
|
|
QTextFormat.BackgroundBrush |
|
|
QTextFormat.BackgroundImageUrl |
Paragraph properties
|
常量 |
描述 |
|---|---|
|
QTextFormat.BlockAlignment |
|
|
QTextFormat.BlockTopMargin |
|
|
QTextFormat.BlockBottomMargin |
|
|
QTextFormat.BlockLeftMargin |
|
|
QTextFormat.BlockRightMargin |
|
|
QTextFormat.TextIndent |
|
|
QTextFormat.TabPositions |
Specifies the tab positions. The tab positions are structs of
|
|
QTextFormat.BlockIndent |
|
|
QTextFormat.LineHeight |
|
|
QTextFormat.LineHeightType |
|
|
QTextFormat.BlockNonBreakableLines |
|
|
QTextFormat.BlockTrailingHorizontalRulerWidth |
The width of a horizontal ruler element. |
|
QTextFormat.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. |
|
QTextFormat.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. |
|
QTextFormat.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. |
|
QTextFormat.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. |
|
QTextFormat.BlockMarker |
|
Character properties
|
常量 |
描述 |
|---|---|
|
QTextFormat.FontFamily |
|
|
QTextFormat.FontFamilies |
|
|
QTextFormat.FontStyleName |
|
|
QTextFormat.FontPointSize |
|
|
QTextFormat.FontPixelSize |
|
|
QTextFormat.FontSizeAdjustment |
Specifies the change in size given to the fontsize already set using or . |
|
QTextFormat.FontFixedPitch |
|
|
QTextFormat.FontWeight |
|
|
QTextFormat.FontItalic |
|
|
QTextFormat.FontUnderline |
This property has been deprecated. Use instead. |
|
QTextFormat.FontOverline |
|
|
QTextFormat.FontStrikeOut |
|
|
QTextFormat.FontCapitalization |
Specifies the capitalization type that is to be applied to the text. |
|
QTextFormat.FontLetterSpacingType |
Specifies the meaning of the property. The default is
|
|
QTextFormat.FontLetterSpacing |
Changes the default spacing between individual letters in the font. The value is specified as a percentage or absolute value, depending on . The default value is 100%. |
|
QTextFormat.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. |
|
QTextFormat.FontStretch |
相当于
|
|
QTextFormat.FontStyleHint |
相当于
|
|
QTextFormat.FontStyleStrategy |
相当于
|
|
QTextFormat.FontKerning |
Specifies whether the font has kerning turned on. |
|
QTextFormat.FontHintingPreference |
Controls the use of hinting according to values of the
|
|
QTextFormat.TextUnderlineColor |
|
|
QTextFormat.TextVerticalAlignment |
|
|
QTextFormat.TextOutline |
|
|
QTextFormat.TextUnderlineStyle |
|
|
QTextFormat.TextToolTip |
Specifies the (optional) tool tip to be displayed for a fragment of text. |
|
QTextFormat.IsAnchor |
|
|
QTextFormat.AnchorHref |
|
|
QTextFormat.AnchorName |
|
|
QTextFormat.ObjectType |
List properties
|
常量 |
描述 |
|---|---|
|
QTextFormat.ListStyle |
Specifies the style used for the items in a list, described by values of the
|
|
QTextFormat.ListIndent |
Specifies the amount of indentation used for a list. |
|
QTextFormat.ListNumberPrefix |
Defines the text which is prepended to item numbers in numeric lists. |
|
QTextFormat.ListNumberSuffix |
Defines the text which is appended to item numbers in numeric lists. |
Table and frame properties
|
常量 |
描述 |
|---|---|
|
QTextFormat.FrameBorder |
|
|
QTextFormat.FrameBorderBrush |
|
|
QTextFormat.FrameBorderStyle |
见
|
|
QTextFormat.FrameBottomMargin |
|
|
QTextFormat.FrameHeight |
|
|
QTextFormat.FrameLeftMargin |
|
|
QTextFormat.FrameMargin |
|
|
QTextFormat.FramePadding |
|
|
QTextFormat.FrameRightMargin |
|
|
QTextFormat.FrameTopMargin |
|
|
QTextFormat.FrameWidth |
|
|
QTextFormat.TableCellSpacing |
|
|
QTextFormat.TableCellPadding |
|
|
QTextFormat.TableColumns |
|
|
QTextFormat.TableColumnWidthConstraints |
|
|
QTextFormat.TableHeaderRowCount |
|
|
QTextFormat.TableBorderCollapse |
Specifies the
|
Table cell properties
|
常量 |
描述 |
|---|---|
|
QTextFormat.TableCellRowSpan |
|
|
QTextFormat.TableCellColumnSpan |
|
|
QTextFormat.TableCellLeftPadding |
|
|
QTextFormat.TableCellRightPadding |
|
|
QTextFormat.TableCellTopPadding |
|
|
QTextFormat.TableCellBottomPadding |
Table cell properties intended for use with
borderCollapse
enabled
|
常量 |
描述 |
|---|---|
|
QTextFormat.TableCellTopBorder |
|
|
QTextFormat.TableCellBottomBorder |
|
|
QTextFormat.TableCellLeftBorder |
|
|
QTextFormat.TableCellRightBorder |
|
|
QTextFormat.TableCellTopBorderStyle |
|
|
QTextFormat.TableCellBottomBorderStyle |
|
|
QTextFormat.TableCellLeftBorderStyle |
|
|
QTextFormat.TableCellRightBorderStyle |
|
|
QTextFormat.TableCellTopBorderBrush |
|
|
QTextFormat.TableCellBottomBorderBrush |
|
|
QTextFormat.TableCellLeftBorderBrush |
|
|
QTextFormat.TableCellRightBorderBrush |
Image properties
|
常量 |
描述 |
|---|---|
|
QTextFormat.ImageName |
The filename or source of the image. |
|
QTextFormat.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. |
|
QTextFormat.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. |
|
QTextFormat.ImageWidth |
|
|
QTextFormat.ImageHeight |
|
|
QTextFormat.ImageQuality |
Selection properties
|
常量 |
描述 |
|---|---|
|
QTextFormat.FullWidthSelection |
When set on the characterFormat of a selection, the whole width of the text will be shown selected. |
Page break properties
|
常量 |
描述 |
|---|---|
|
QTextFormat.PageBreakPolicy |
Specifies how pages are broken. See the
|
|
QTextFormat.UserProperty |
另请参阅
PySide2.QtGui.QTextFormat.
ObjectTypes
¶
This enum describes what kind of
QTextObject
this format is associated with.
|
常量 |
描述 |
|---|---|
|
QTextFormat.NoObject |
|
|
QTextFormat.ImageObject |
|
|
QTextFormat.TableObject |
|
|
QTextFormat.TableCellObject |
|
|
QTextFormat.UserObject |
The first object that can be used for application-specific purposes. |
PySide2.QtGui.QTextFormat.
PageBreakFlag
¶
This enum describes how page breaking is performed when printing. It maps to the corresponding css properties.
|
常量 |
描述 |
|---|---|
|
QTextFormat.PageBreak_Auto |
The page break is determined automatically depending on the available space on the current page |
|
QTextFormat.PageBreak_AlwaysBefore |
The page is always broken before the paragraph/table |
|
QTextFormat.PageBreak_AlwaysAfter |
A new page is always started after the paragraph/table |
另请参阅
pageBreakPolicy()
pageBreakPolicy()
PageBreakPolicy
PySide2.QtGui.QTextFormat.
background
(
)
¶
Returns the brush used to paint the document’s background.
PySide2.QtGui.QTextFormat.
boolProperty
(
propertyId
)
¶
propertyId
–
int
bool
Returns the value of the property specified by
propertyId
. If the property isn’t of QTextFormat::Bool type, false is returned instead.
PySide2.QtGui.QTextFormat.
brushProperty
(
propertyId
)
¶
propertyId
–
int
Returns the value of the property given by
propertyId
; if the property isn’t of
Brush
type,
NoBrush
被返回取而代之。
PySide2.QtGui.QTextFormat.
clearBackground
(
)
¶
Clears the brush used to paint the document’s background. The default brush will be used.
PySide2.QtGui.QTextFormat.
clearForeground
(
)
¶
Clears the brush used to paint the document’s foreground. The default brush will be used.
PySide2.QtGui.QTextFormat.
clearProperty
(
propertyId
)
¶
propertyId
–
int
Clears the value of the property given by
propertyId
另请参阅
特性
PySide2.QtGui.QTextFormat.
colorProperty
(
propertyId
)
¶
propertyId
–
int
Returns the value of the property given by
propertyId
; if the property isn’t of
Color
type, an invalid color is returned instead.
PySide2.QtGui.QTextFormat.
doubleProperty
(
propertyId
)
¶
propertyId
–
int
qreal
Returns the value of the property specified by
propertyId
. If the property isn’t of
Double
or
Float
type, 0 is returned instead.
PySide2.QtGui.QTextFormat.
foreground
(
)
¶
Returns the brush used to render foreground details, such as text, frame outlines, and table borders.
PySide2.QtGui.QTextFormat.
hasProperty
(
propertyId
)
¶
propertyId
–
int
bool
返回
true
if the text format has a property with the given
propertyId
;否则返回
false
.
另请参阅
properties()
特性
PySide2.QtGui.QTextFormat.
intProperty
(
propertyId
)
¶
propertyId
–
int
int
Returns the value of the property specified by
propertyId
. If the property is not of QTextFormat::Integer type, 0 is returned instead.
PySide2.QtGui.QTextFormat.
isBlockFormat
(
)
¶
bool
返回
true
if this text format is a
BlockFormat
;否则返回
false
.
PySide2.QtGui.QTextFormat.
isCharFormat
(
)
¶
bool
返回
true
if this text format is a
CharFormat
;否则返回
false
.
PySide2.QtGui.QTextFormat.
isEmpty
(
)
¶
bool
Returns true if the format does not store any properties; false otherwise.
PySide2.QtGui.QTextFormat.
isFrameFormat
(
)
¶
bool
返回
true
if this text format is a
FrameFormat
;否则返回
false
.
PySide2.QtGui.QTextFormat.
isImageFormat
(
)
¶
bool
返回
true
if this text format is an image format; otherwise returns
false
.
PySide2.QtGui.QTextFormat.
isListFormat
(
)
¶
bool
返回
true
if this text format is a
ListFormat
;否则返回
false
.
PySide2.QtGui.QTextFormat.
isTableCellFormat
(
)
¶
bool
返回
true
if this text format is a
TableCellFormat
;否则返回
false
.
PySide2.QtGui.QTextFormat.
isTableFormat
(
)
¶
bool
返回
true
if this text format is a
TableFormat
;否则返回
false
.
PySide2.QtGui.QTextFormat.
isValid
(
)
¶
bool
返回
true
if the format is valid (i.e. is not
InvalidFormat
); otherwise returns
false
.
PySide2.QtGui.QTextFormat.
layoutDirection
(
)
¶
LayoutDirection
Returns the document’s layout direction.
另请参阅
PySide2.QtGui.QTextFormat.
lengthProperty
(
propertyId
)
¶
propertyId
–
int
Returns the value of the property given by
propertyId
.
PySide2.QtGui.QTextFormat.
lengthVectorProperty
(
propertyId
)
¶
propertyId
–
int
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.
PySide2.QtGui.QTextFormat.
merge
(
other
)
¶
other
–
QTextFormat
Merges the
other
format with this format; where there are conflicts the
other
format takes precedence.
PySide2.QtGui.QTextFormat.
objectIndex
(
)
¶
int
Returns the index of the format object, or -1 if the format object is invalid.
另请参阅
PySide2.QtGui.QTextFormat.
objectType
(
)
¶
int
Returns the text format’s object type.
另请参阅
ObjectTypes
setObjectType()
PySide2.QtGui.QTextFormat.
__ne__
(
rhs
)
¶
rhs
–
QTextFormat
bool
返回
true
if this text format is different from the
other
text format.
PySide2.QtGui.QTextFormat.
__eq__
(
rhs
)
¶
rhs
–
QTextFormat
bool
返回
true
if this text format is the same as the
other
text format.
PySide2.QtGui.QTextFormat.
penProperty
(
propertyId
)
¶
propertyId
–
int
Returns the value of the property given by
propertyId
; if the property isn’t of
Pen
type,
NoPen
被返回取而代之。
PySide2.QtGui.QTextFormat.
properties
(
)
¶
Returns a map with all properties of this text format.
PySide2.QtGui.QTextFormat.
特性
(
propertyId
)
¶
propertyId
–
int
object
Returns the property specified by the given
propertyId
.
另请参阅
PySide2.QtGui.QTextFormat.
propertyCount
(
)
¶
int
Returns the number of properties stored in the format.
PySide2.QtGui.QTextFormat.
setBackground
(
brush
)
¶
brush
–
QBrush
Sets the brush use to paint the document’s background to the
brush
指定。
PySide2.QtGui.QTextFormat.
setForeground
(
brush
)
¶
brush
–
QBrush
Sets the foreground brush to the specified
brush
. The foreground brush is mostly used to render text.
PySide2.QtGui.QTextFormat.
setLayoutDirection
(
direction
)
¶
direction
–
LayoutDirection
Sets the document’s layout direction to the specified
direction
.
另请参阅
PySide2.QtGui.QTextFormat.
setObjectIndex
(
object
)
¶
object
–
int
Sets the format object’s object
index
.
另请参阅
PySide2.QtGui.QTextFormat.
setObjectType
(
type
)
¶
type
–
int
Sets the text format’s object type to
type
.
另请参阅
ObjectTypes
objectType()
PySide2.QtGui.QTextFormat.
setProperty
(
propertyId
,
value
)
¶
propertyId
–
int
value – object
PySide2.QtGui.QTextFormat.
setProperty
(
propertyId
,
lengths
)
¶
propertyId
–
int
lengths –
PySide2.QtGui.QTextFormat.
stringProperty
(
propertyId
)
¶
propertyId
–
int
unicode
Returns the value of the property given by
propertyId
; if the property isn’t of
字符串
type, an empty string is returned instead.
PySide2.QtGui.QTextFormat.
swap
(
other
)
¶
other
–
QTextFormat
Swaps this text format with
other
。此函数非常快,且从不失败。
PySide2.QtGui.QTextFormat.
toBlockFormat
(
)
¶
Returns this format as a block format.
PySide2.QtGui.QTextFormat.
toCharFormat
(
)
¶
Returns this format as a character format.
PySide2.QtGui.QTextFormat.
toFrameFormat
(
)
¶
Returns this format as a frame format.
PySide2.QtGui.QTextFormat.
toImageFormat
(
)
¶
Returns this format as an image format.
PySide2.QtGui.QTextFormat.
toListFormat
(
)
¶
Returns this format as a list format.
PySide2.QtGui.QTextFormat.
toTableCellFormat
(
)
¶
Returns this format as a table cell format.
PySide2.QtGui.QTextFormat.
toTableFormat
(
)
¶
Returns this format as a table format.
PySide2.QtGui.QTextFormat.
type
(
)
¶
int
Returns the type of this format.
另请参阅
FormatType