QTextBlockFormat 類

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

頭: #include <QTextBlockFormat>
qmake: QT += gui
繼承: QTextFormat

注意: 此類的所有函數 可重入 .

公共類型

enum LineHeightTypes { SingleHeight, ProportionalHeight, FixedHeight, MinimumHeight, LineDistanceHeight }

公共函數

QTextBlockFormat ()
Qt::Alignment alignment () const
qreal bottomMargin () const
int headingLevel () const
int indent () const
bool isValid () const
qreal leftMargin () const
qreal lineHeight (qreal scriptLineHeight , qreal scaling = 1.0) const
qreal lineHeight () const
int lineHeightType () const
bool nonBreakableLines () const
QTextFormat::PageBreakFlags pageBreakPolicy () const
qreal rightMargin () const
void setAlignment (Qt::Alignment alignment )
void setBottomMargin (qreal margin )
void setHeadingLevel (int level )
void setIndent (int indentation )
void setLeftMargin (qreal margin )
void setLineHeight (qreal height , int heightType )
void setNonBreakableLines (bool b )
void setPageBreakPolicy (QTextFormat::PageBreakFlags policy )
void setRightMargin (qreal margin )
void setTabPositions (const QList<QTextOption::Tab> & tabs )
void setTextIndent (qreal indent )
void setTopMargin (qreal margin )
QList<QTextOption::Tab> tabPositions () const
qreal textIndent () const
qreal topMargin () const

詳細描述

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 () and retrieved via lineHeight () 和 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 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.

另請參閱 QTextBlock and QTextCharFormat .

成員類型文檔編製

enum 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:: QTextBlockFormat ()

構造新的 QTextBlockFormat .

Qt::Alignment QTextBlockFormat:: alignment () const

返迴段落的對齊方式。

另請參閱 setAlignment ().

qreal QTextBlockFormat:: bottomMargin () const

返迴段落的底邊距。

另請參閱 setBottomMargin () 和 topMargin ().

int QTextBlockFormat:: headingLevel () const

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

該函數在 Qt 5.12 引入。

另請參閱 setHeadingLevel ().

int QTextBlockFormat:: indent () const

Returns the paragraph's indent.

另請參閱 setIndent ().

bool QTextBlockFormat:: isValid () const

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

qreal QTextBlockFormat:: leftMargin () const

返迴段落的左邊距。

另請參閱 setLeftMargin (), rightMargin (),和 indent ().

qreal QTextBlockFormat:: lineHeight ( qreal scriptLineHeight , qreal scaling = 1.0) const

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.

該函數在 Qt 4.8 引入。

另請參閱 LineHeightTypes , setLineHeight (),和 lineHeightType ().

qreal QTextBlockFormat:: lineHeight () const

This returns the LineHeight property for the paragraph.

該函數在 Qt 4.8 引入。

另請參閱 LineHeightTypes , setLineHeight (),和 lineHeightType ().

int QTextBlockFormat:: lineHeightType () const

This returns the LineHeightType property of the paragraph.

該函數在 Qt 4.8 引入。

另請參閱 LineHeightTypes , setLineHeight (),和 lineHeight ().

bool QTextBlockFormat:: nonBreakableLines () const

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

另請參閱 setNonBreakableLines ().

QTextFormat::PageBreakFlags QTextBlockFormat:: pageBreakPolicy () const

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

該函數在 Qt 4.2 引入。

另請參閱 setPageBreakPolicy ().

qreal QTextBlockFormat:: rightMargin () const

Returns the paragraph's right margin.

另請參閱 setRightMargin () 和 leftMargin ().

void QTextBlockFormat:: setAlignment ( Qt::Alignment alignment )

Sets the paragraph's alignment .

另請參閱 alignment ().

void QTextBlockFormat:: setBottomMargin ( qreal margin )

Sets the paragraph's bottom margin .

另請參閱 bottomMargin (), setTopMargin (), setLeftMargin (),和 setRightMargin ().

void QTextBlockFormat:: setHeadingLevel ( int level )

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

該函數在 Qt 5.12 引入。

另請參閱 headingLevel ().

void QTextBlockFormat:: setIndent ( int indentation )

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

void QTextBlockFormat:: setLeftMargin ( qreal margin )

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

另請參閱 leftMargin (), setRightMargin (), setTopMargin (),和 setBottomMargin ().

void QTextBlockFormat:: setLineHeight ( qreal 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 ().

void QTextBlockFormat:: setNonBreakableLines ( bool b )

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

另請參閱 nonBreakableLines ().

void QTextBlockFormat:: setPageBreakPolicy ( QTextFormat::PageBreakFlags policy )

Sets the page break policy for the paragraph to policy .

該函數在 Qt 4.2 引入。

另請參閱 pageBreakPolicy ().

void QTextBlockFormat:: setRightMargin ( qreal margin )

Sets the paragraph's right margin .

另請參閱 rightMargin (), setLeftMargin (), setTopMargin (),和 setBottomMargin ().

void QTextBlockFormat:: setTabPositions (const QList < QTextOption::Tab > & tabs )

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

該函數在 Qt 4.4 引入。

另請參閱 tabPositions ().

void QTextBlockFormat:: setTextIndent ( qreal indent )

設置 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 (),和 setBottomMargin ().

void QTextBlockFormat:: setTopMargin ( qreal margin )

Sets the paragraph's top margin .

另請參閱 topMargin (), setBottomMargin (), setLeftMargin (),和 setRightMargin ().

QList < QTextOption::Tab > QTextBlockFormat:: tabPositions () const

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

該函數在 Qt 4.4 引入。

另請參閱 setTabPositions ().

qreal QTextBlockFormat:: textIndent () const

Returns the paragraph's text indent.

另請參閱 setTextIndent ().

qreal QTextBlockFormat:: topMargin () const

Returns the paragraph's top margin.

另請參閱 setTopMargin () 和 bottomMargin ().