内容表

上一话题

QTextBlock

下一话题

QTextBlockGroup

QTextBlockFormat

QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument . 更多

Inheritance diagram of PySide2.QtGui.QTextBlockFormat

概要

函数

详细描述

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 associated QTextBlockFormat 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 by setTopMargin() , setBottomMargin() , setLeftMargin() , setRightMargin() . Overall indentation is set with setIndent() , the indentation of the first line with setTextIndent() .

Line spacing is set with setLineHeight() and retrieved via lineHeight() and lineHeightType() . The types of line spacing available are in the LineHeightTypes 枚举。

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 the setProperty() 函数采用 OutlinePen , ForegroundBrush ,和 BackgroundBrush 特性 值。

If a text block is part of a list, it can also have a list format that is accessible with the listFormat() function.

class QTextBlockFormat

QTextBlockFormat(QTextBlockFormat)

QTextBlockFormat(fmt)

param QTextBlockFormat

QTextBlockFormat

param fmt

QTextFormat

构造新 QTextBlockFormat .

PySide2.QtGui.QTextBlockFormat. LineHeightTypes

This enum describes the various types of line spacing support paragraphs can have.

常量

描述

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).

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 the style() for the entire list.

常量

描述

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.

另请参阅

style()

New in version 5.14.

PySide2.QtGui.QTextBlockFormat. alignment ( )
返回类型

Alignment

Returns the paragraph’s alignment.

另请参阅

setAlignment()

PySide2.QtGui.QTextBlockFormat. bottomMargin ( )
返回类型

qreal

Returns the paragraph’s bottom margin.

PySide2.QtGui.QTextBlockFormat. headingLevel ( )
返回类型

int

Returns the paragraph’s heading level if it is a heading, or 0 if not.

另请参阅

setHeadingLevel()

PySide2.QtGui.QTextBlockFormat. indent ( )
返回类型

int

Returns the paragraph’s indent.

另请参阅

setIndent()

PySide2.QtGui.QTextBlockFormat. leftMargin ( )
返回类型

qreal

Returns the paragraph’s left margin.

PySide2.QtGui.QTextBlockFormat. lineHeight ( scriptLineHeight , scaling )
参数
  • scriptLineHeight qreal

  • scaling qreal

返回类型

qreal

Returns the height of the lines in the paragraph based on the height of the script line given by scriptLineHeight and the specified scaling factor.

The value that is returned is also dependent on the given LineHeightType of the paragraph as well as the LineHeight 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.

另请参阅

LineHeightTypes setLineHeight() lineHeightType()

PySide2.QtGui.QTextBlockFormat. lineHeight ( )
返回类型

qreal

This returns the LineHeight property for the paragraph.

另请参阅

LineHeightTypes setLineHeight() lineHeightType()

PySide2.QtGui.QTextBlockFormat. lineHeightType ( )
返回类型

int

This returns the LineHeightType property of the paragraph.

另请参阅

LineHeightTypes setLineHeight() lineHeight()

PySide2.QtGui.QTextBlockFormat. marker ( )
返回类型

MarkerType

Returns the paragraph’s marker if one has been set, or NoMarker if not.

另请参阅

setMarker()

PySide2.QtGui.QTextBlockFormat. nonBreakableLines ( )
返回类型

bool

返回 true if the lines in the paragraph are non-breakable; otherwise returns false .

PySide2.QtGui.QTextBlockFormat. pageBreakPolicy ( )
返回类型

PageBreakFlags

Returns the currently set page break policy for the paragraph. The default is PageBreak_Auto .

PySide2.QtGui.QTextBlockFormat. rightMargin ( )
返回类型

qreal

Returns the paragraph’s right margin.

PySide2.QtGui.QTextBlockFormat. setAlignment ( alignment )
参数

alignment Alignment

Sets the paragraph’s alignment .

另请参阅

alignment()

PySide2.QtGui.QTextBlockFormat. setBottomMargin ( margin )
参数

margin qreal

Sets the paragraph’s bottom margin .

PySide2.QtGui.QTextBlockFormat. setHeadingLevel ( alevel )
参数

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; however fromHtml() 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).

另请参阅

headingLevel()

PySide2.QtGui.QTextBlockFormat. setIndent ( indent )
参数

indent int

Sets the paragraph’s indentation . Margins are set independently of indentation with setLeftMargin() and setTextIndent() indentation is an integer that is multiplied with the document-wide standard indent, resulting in the actual indent of the paragraph.

PySide2.QtGui.QTextBlockFormat. setLeftMargin ( margin )
参数

margin qreal

Sets the paragraph’s left margin . Indentation can be applied separately with setIndent() .

PySide2.QtGui.QTextBlockFormat. setLineHeight ( height , heightType )
参数
  • height qreal

  • heightType int

Sets the line height for the paragraph to the value given by height which is dependent on heightType in the way described by the LineHeightTypes 枚举。

另请参阅

LineHeightTypes lineHeight() lineHeightType()

PySide2.QtGui.QTextBlockFormat. setMarker ( marker )
参数

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 is NoMarker .

另请参阅

marker()

PySide2.QtGui.QTextBlockFormat. setNonBreakableLines ( b )
参数

b bool

b is true, the lines in the paragraph are treated as non-breakable; otherwise they are breakable.

PySide2.QtGui.QTextBlockFormat. setPageBreakPolicy ( flags )
参数

flags PageBreakFlags

Sets the page break policy for the paragraph to policy .

另请参阅

pageBreakPolicy()

PySide2.QtGui.QTextBlockFormat. setRightMargin ( margin )
参数

margin qreal

Sets the paragraph’s right margin .

PySide2.QtGui.QTextBlockFormat. setTabPositions ( tabs )
参数

tabs

Sets the tab positions for the text block to those specified by tabs .

另请参阅

tabPositions()

PySide2.QtGui.QTextBlockFormat. setTextIndent ( aindent )
参数

aindent qreal

设置 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 )
参数

margin qreal

Sets the paragraph’s top margin .

PySide2.QtGui.QTextBlockFormat. tabPositions ( )
返回类型

Returns a list of tab positions defined for the text block.

另请参阅

setTabPositions()

PySide2.QtGui.QTextBlockFormat. textIndent ( )
返回类型

qreal

Returns the paragraph’s text indent.

另请参阅

setTextIndent()

PySide2.QtGui.QTextBlockFormat. topMargin ( )
返回类型

qreal

Returns the paragraph’s top margin.