QTextBlockFormat Class Reference

[ QtGui module]

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

继承 QTextFormat .

类型

方法


详细描述

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

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 () 和 retrieved via lineHeight () 和 lineHeightType ()。 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() ,和 other aspects of the text's appearance can be customized by using the setProperty() 函数采用 OutlinePen , ForegroundBrush , and BackgroundBrush QTextFormat.Property 值。

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


类型文档编制

QTextBlockFormat.LineHeightTypes

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

常量 描述
QTextBlockFormat.SingleHeight 0 This is the default line height: single spacing.
QTextBlockFormat.ProportionalHeight 1 This sets the spacing proportional to the line (in percentage). For example, set to 200 for double spacing.
QTextBlockFormat.FixedHeight 2 This sets the line height to a fixed line height (in pixels).
QTextBlockFormat.MinimumHeight 3 This sets the minimum line height (in pixels).
QTextBlockFormat.LineDistanceHeight 4 This adds the specified height between lines (in pixels).

该枚举在 Qt 4.8 引入或被修改。

另请参阅 lineHeight (), lineHeightType (),和 setLineHeight ().


方法文档编制

QTextBlockFormat.__init__ ( self )

构造新 QTextBlockFormat .

QTextBlockFormat.__init__ ( self , QTextBlockFormat )

Qt.Alignment QTextBlockFormat.alignment ( self )

返回段落的对齐方式。

另请参阅 setAlignment ().

float QTextBlockFormat.bottomMargin ( self )

返回段落的底边距。

另请参阅 setBottomMargin () 和 topMargin ().

int QTextBlockFormat.indent ( self )

Returns the paragraph's indent.

另请参阅 setIndent ().

bool QTextBlockFormat.isValid ( self )

Returns true if this block format is valid; otherwise returns false.

float QTextBlockFormat.leftMargin ( self )

Returns the paragraph's left margin.

另请参阅 setLeftMargin (), rightMargin (),和 indent ().

float QTextBlockFormat.lineHeight ( self , float  scriptLineHeight , float  scaling )

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

The value that is returned is also dependent on the given LineHeightType 的 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.

该函数在 Qt 4.8 引入。

另请参阅 LineHeightTypes , setLineHeight (), and lineHeightType ().

float QTextBlockFormat.lineHeight ( self )

This returns the LineHeight property for the paragraph.

该函数在 Qt 4.8 引入。

另请参阅 LineHeightTypes , setLineHeight (), and lineHeightType ().

int QTextBlockFormat.lineHeightType ( self )

This returns the LineHeightType 特性为 paragraph.

该函数在 Qt 4.8 引入。

另请参阅 LineHeightTypes , setLineHeight (), and lineHeight ().

bool QTextBlockFormat.nonBreakableLines ( self )

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

另请参阅 setNonBreakableLines ().

QTextFormat.PageBreakFlags QTextBlockFormat.pageBreakPolicy ( self )

Returns the currently set page break policy for the paragraph. 默认为 QTextFormat.PageBreak_Auto .

该函数在 Qt 4.2 引入。

另请参阅 setPageBreakPolicy ().

float QTextBlockFormat.rightMargin ( self )

Returns the paragraph's right margin.

另请参阅 setRightMargin () 和 leftMargin ().

QTextBlockFormat.setAlignment ( self , Qt.Alignment   aalignment )

Sets the paragraph's alignment .

另请参阅 alignment ().

QTextBlockFormat.setBottomMargin ( self , float  margin )

Sets the paragraph's bottom margin .

另请参阅 bottomMargin (), setTopMargin (), setLeftMargin (),和 setRightMargin ().

QTextBlockFormat.setIndent ( self , int  aindent )

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

另请参阅 indent () 和 QTextDocument.indentWidth ().

QTextBlockFormat.setLeftMargin ( self , float  margin )

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

另请参阅 leftMargin (), setRightMargin (), setTopMargin (), and setBottomMargin ().

QTextBlockFormat.setLineHeight ( self , float  height , int  heightType )

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 枚举。

该函数在 Qt 4.8 引入。

另请参阅 LineHeightTypes , lineHeight (),和 lineHeightType ().

QTextBlockFormat.setNonBreakableLines ( self , bool  b )

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

另请参阅 nonBreakableLines ().

QTextBlockFormat.setPageBreakPolicy ( self , QTextFormat.PageBreakFlags   flags )

Sets the page break policy for the paragraph to policy .

该函数在 Qt 4.2 引入。

另请参阅 pageBreakPolicy ().

QTextBlockFormat.setRightMargin ( self , float  margin )

Sets the paragraph's right margin .

另请参阅 rightMargin (), setLeftMargin (), setTopMargin (),和 setBottomMargin ().

QTextBlockFormat.setTabPositions ( self , list-of-QTextOption.Tab  tabs )

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

该函数在 Qt 4.4 引入。

另请参阅 tabPositions ().

QTextBlockFormat.setTextIndent ( self , float  margin )

设置 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.

另请参阅 textIndent (), setLeftMargin (), setRightMargin (), setTopMargin (), and setBottomMargin ().

QTextBlockFormat.setTopMargin ( self , float  margin )

Sets the paragraph's top margin .

另请参阅 topMargin (), setBottomMargin (), setLeftMargin (), and setRightMargin ().

list-of-QTextOption.Tab QTextBlockFormat.tabPositions ( self )

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

该函数在 Qt 4.4 引入。

另请参阅 setTabPositions ().

float QTextBlockFormat.textIndent ( self )

Returns the paragraph's text indent.

另请参阅 setTextIndent ().

float QTextBlockFormat.topMargin ( self )

Returns the paragraph's top margin.

另请参阅 setTopMargin () 和 bottomMargin ().