QTextBlockFormat¶
The
QTextBlockFormat
class provides formatting information for blocks of text in aQTextDocument
. More…
Synopsis¶
Functions¶
def
alignment
()def
bottomMargin
()def
headingLevel
()def
indent
()def
leftMargin
()def
lineHeight
()def
lineHeight
(scriptLineHeight, scaling)def
lineHeightType
()def
marker
()def
nonBreakableLines
()def
pageBreakPolicy
()def
rightMargin
()def
setAlignment
(alignment)def
setBottomMargin
(margin)def
setHeadingLevel
(alevel)def
setIndent
(indent)def
setLeftMargin
(margin)def
setLineHeight
(height, heightType)def
setMarker
(marker)def
setNonBreakableLines
(b)def
setPageBreakPolicy
(flags)def
setRightMargin
(margin)def
setTabPositions
(tabs)def
setTextIndent
(aindent)def
setTopMargin
(margin)def
tabPositions
()def
textIndent
()def
topMargin
()
Detailed Description¶
A document is composed of a list of blocks, represented by
QTextBlock
objects. Each block can contain an item of some kind, such as a paragraph of text, a table, a list, or an image. Every block has an associatedQTextBlockFormat
that specifies its characteristics.To cater for left-to-right and right-to-left languages you can set a block’s direction with setDirection(). Paragraph alignment is set with
setAlignment()
. Margins are controlled bysetTopMargin()
,setBottomMargin()
,setLeftMargin()
,setRightMargin()
. Overall indentation is set withsetIndent()
, the indentation of the first line withsetTextIndent()
.Line spacing is set with
setLineHeight()
and retrieved vialineHeight()
andlineHeightType()
. The types of line spacing available are in theLineHeightTypes
enum.Line breaking can be enabled and disabled with
setNonBreakableLines()
.The brush used to paint the paragraph’s background is set with
setBackground()
, and other aspects of the text’s appearance can be customized by using thesetProperty()
function with theOutlinePen
,ForegroundBrush
, andBackgroundBrush
Property
values.If a text block is part of a list, it can also have a list format that is accessible with the listFormat() function.
See also
- class PySide2.QtGui.QTextBlockFormat¶
PySide2.QtGui.QTextBlockFormat(QTextBlockFormat)
PySide2.QtGui.QTextBlockFormat(fmt)
- param QTextBlockFormat:
- param fmt:
Constructs a new
QTextBlockFormat
.
- PySide2.QtGui.QTextBlockFormat.LineHeightTypes¶
This enum describes the various types of line spacing support paragraphs can have.
Constant
Description
QTextBlockFormat.SingleHeight
This is the default line height: single spacing.
QTextBlockFormat.ProportionalHeight
This sets the spacing proportional to the line (in percentage). For example, set to 200 for double spacing.
QTextBlockFormat.FixedHeight
This sets the line height to a fixed line height (in pixels).
QTextBlockFormat.MinimumHeight
This sets the minimum line height (in pixels).
QTextBlockFormat.LineDistanceHeight
This adds the specified height between lines (in pixels).
See also
New in version 4.8.
- PySide2.QtGui.QTextBlockFormat.MarkerType¶
This enum describes the types of markers a list item can have. If a list item (a paragraph for which
textList()
returns the list) has a marker, it is rendered instead of the normal bullet. In this way, checkable list items can be mixed with plain list items in the same list, overriding the type of bullet specified by thestyle()
for the entire list.Constant
Description
QTextBlockFormat.MarkerType.NoMarker
This is the default: the list item’s bullet will be shown.
QTextBlockFormat.MarkerType.Unchecked
Instead of the list item’s bullet, an unchecked checkbox will be shown.
QTextBlockFormat.MarkerType.Checked
Instead of the list item’s bullet, a checked checkbox will be shown.
In the future, this may be extended to specify other types of paragraph decorations.
See also
New in version 5.14.
- PySide2.QtGui.QTextBlockFormat.alignment()¶
- Return type:
Alignment
Returns the paragraph’s alignment.
See also
- PySide2.QtGui.QTextBlockFormat.bottomMargin()¶
- Return type:
float
Returns the paragraph’s bottom margin.
See also
- PySide2.QtGui.QTextBlockFormat.headingLevel()¶
- Return type:
int
Returns the paragraph’s heading level if it is a heading, or 0 if not.
See also
- PySide2.QtGui.QTextBlockFormat.indent()¶
- Return type:
int
Returns the paragraph’s indent.
See also
- PySide2.QtGui.QTextBlockFormat.leftMargin()¶
- Return type:
float
Returns the paragraph’s left margin.
See also
- PySide2.QtGui.QTextBlockFormat.lineHeight(scriptLineHeight, scaling)¶
- Parameters:
scriptLineHeight – float
scaling – float
- Return type:
float
Returns the height of the lines in the paragraph based on the height of the script line given by
scriptLineHeight
and the specifiedscaling
factor.The value that is returned is also dependent on the given
LineHeightType
of the paragraph as well as theLineHeight
setting that has been set for the paragraph.The scaling is needed for heights that include a fixed number of pixels, to scale them appropriately for printing.
See also
LineHeightTypes
setLineHeight()
lineHeightType()
- PySide2.QtGui.QTextBlockFormat.lineHeight()
- Return type:
float
This returns the
LineHeight
property for the paragraph.See also
LineHeightTypes
setLineHeight()
lineHeightType()
- PySide2.QtGui.QTextBlockFormat.lineHeightType()¶
- Return type:
int
This returns the
LineHeightType
property of the paragraph.See also
LineHeightTypes
setLineHeight()
lineHeight()
- PySide2.QtGui.QTextBlockFormat.marker()¶
- Return type:
Returns the paragraph’s marker if one has been set, or
NoMarker
if not.See also
- PySide2.QtGui.QTextBlockFormat.nonBreakableLines()¶
- Return type:
bool
Returns
true
if the lines in the paragraph are non-breakable; otherwise returnsfalse
.See also
- PySide2.QtGui.QTextBlockFormat.pageBreakPolicy()¶
- Return type:
PageBreakFlags
Returns the currently set page break policy for the paragraph. The default is
PageBreak_Auto
.See also
- PySide2.QtGui.QTextBlockFormat.rightMargin()¶
- Return type:
float
Returns the paragraph’s right margin.
See also
- PySide2.QtGui.QTextBlockFormat.setAlignment(alignment)¶
- Parameters:
alignment –
Alignment
Sets the paragraph’s
alignment
.See also
- PySide2.QtGui.QTextBlockFormat.setBottomMargin(margin)¶
- Parameters:
margin – float
Sets the paragraph’s bottom
margin
.
- PySide2.QtGui.QTextBlockFormat.setHeadingLevel(alevel)¶
- Parameters:
alevel – int
Sets the paragraph’s heading
level
, where 1 is the highest-level heading type (usually with the largest possible heading font size), and increasing values are progressively deeper into the document (and usually with smaller font sizes). For example when reading an HTML H1 tag, the heading level is set to 1. Setting the heading level does not automatically change the font size; howeverfromHtml()
sets both the heading level and the font size simultaneously.If the paragraph is not a heading, the level should be set to 0 (the default).
See also
- PySide2.QtGui.QTextBlockFormat.setIndent(indent)¶
- Parameters:
indent – int
Sets the paragraph’s
indentation
. Margins are set independently of indentation withsetLeftMargin()
andsetTextIndent()
. Theindentation
is an integer that is multiplied with the document-wide standard indent, resulting in the actual indent of the paragraph.See also
- PySide2.QtGui.QTextBlockFormat.setLeftMargin(margin)¶
- Parameters:
margin – float
Sets the paragraph’s left
margin
. Indentation can be applied separately withsetIndent()
.
- PySide2.QtGui.QTextBlockFormat.setLineHeight(height, heightType)¶
- Parameters:
height – float
heightType – int
Sets the line height for the paragraph to the value given by
height
which is dependent onheightType
in the way described by theLineHeightTypes
enum.See also
LineHeightTypes
lineHeight()
lineHeightType()
- PySide2.QtGui.QTextBlockFormat.setMarker(marker)¶
- Parameters:
marker –
MarkerType
Sets the type of adornment that should be rendered alongside the paragraph to
marker
. For example, a list item can be adorned with a checkbox, either checked or unchecked, as a replacement for its bullet. The default isNoMarker
.See also
- PySide2.QtGui.QTextBlockFormat.setNonBreakableLines(b)¶
- Parameters:
b – bool
If
b
is true, the lines in the paragraph are treated as non-breakable; otherwise they are breakable.See also
- PySide2.QtGui.QTextBlockFormat.setPageBreakPolicy(flags)¶
- Parameters:
flags –
PageBreakFlags
Sets the page break policy for the paragraph to
policy
.See also
- PySide2.QtGui.QTextBlockFormat.setRightMargin(margin)¶
- Parameters:
margin – float
Sets the paragraph’s right
margin
.
- PySide2.QtGui.QTextBlockFormat.setTabPositions(tabs)¶
- Parameters:
tabs –
Sets the tab positions for the text block to those specified by
tabs
.See also
- PySide2.QtGui.QTextBlockFormat.setTextIndent(aindent)¶
- Parameters:
aindent – float
Sets the
indent
for the first line in the block. This allows the first line of a paragraph to be indented differently to the other lines, enhancing the readability of the text.
- PySide2.QtGui.QTextBlockFormat.setTopMargin(margin)¶
- Parameters:
margin – float
Sets the paragraph’s top
margin
.
- PySide2.QtGui.QTextBlockFormat.tabPositions()¶
- Return type:
Returns a list of tab positions defined for the text block.
See also
- PySide2.QtGui.QTextBlockFormat.textIndent()¶
- Return type:
float
Returns the paragraph’s text indent.
See also
- PySide2.QtGui.QTextBlockFormat.topMargin()¶
- Return type:
float
Returns the paragraph’s top margin.
See also
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.