QTextBlockFormat Class

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

头文件: #include <QTextBlockFormat>
qmake: QT += gui
基类: QTextFormat

Note: All functions in this class are reentrant.

公有类型

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

公有函数

QTextBlockFormat()
Qt::Alignment alignment() const
qreal bottomMargin() const
int indent() const
bool isValid() const
qreal leftMargin() const
qreal lineHeight(qreal scriptLineHeight, qreal scaling) const
qreal lineHeight() const
int lineHeightType() const
bool nonBreakableLines() const
PageBreakFlags pageBreakPolicy() const
qreal rightMargin() const
void setAlignment(Qt::Alignment alignment)
void setBottomMargin(qreal margin)
void setIndent(int indentation)
void setLeftMargin(qreal margin)
void setLineHeight(qreal height, int heightType)
void setNonBreakableLines(bool b)
void setPageBreakPolicy(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() and lineHeightType(). The types of line spacing available are in the LineHeightTypes 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 the setProperty() function with the OutlinePen, ForegroundBrush, and BackgroundBrush QTextFormat::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.

参见 QTextBlock and QTextCharFormat.

成员类型

enum QTextBlockFormat::LineHeightTypes

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

ConstantValueDescription
QTextBlockFormat::SingleHeight0This is the default line height: single spacing.
QTextBlockFormat::ProportionalHeight1This sets the spacing proportional to the line (in percentage). For example, set to 200 for double spacing.
QTextBlockFormat::FixedHeight2This sets the line height to a fixed line height (in pixels).
QTextBlockFormat::MinimumHeight3This sets the minimum line height (in pixels).
QTextBlockFormat::LineDistanceHeight4This adds the specified height between lines (in pixels).

This enum was introduced or modified in Qt 4.8.

参见 lineHeight(), lineHeightType(), and setLineHeight().

成员函数

QTextBlockFormat::QTextBlockFormat()

Constructs a new QTextBlockFormat.

Qt::Alignment QTextBlockFormat::alignment() const

Returns the paragraph's alignment.

参见 setAlignment().

qreal QTextBlockFormat::bottomMargin() const

Returns the paragraph's bottom margin.

参见 setBottomMargin() and topMargin().

int QTextBlockFormat::indent() const

Returns the paragraph's indent.

参见 setIndent().

bool QTextBlockFormat::isValid() const

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

qreal QTextBlockFormat::leftMargin() const

Returns the paragraph's left margin.

参见 setLeftMargin(), rightMargin(), and indent().

qreal QTextBlockFormat::lineHeight(qreal scriptLineHeight, qreal scaling) 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.

This function was introduced in Qt 4.8.

参见 LineHeightTypes, setLineHeight(), and lineHeightType().

qreal QTextBlockFormat::lineHeight() const

This returns the LineHeight property for the paragraph.

This function was introduced in Qt 4.8.

参见 LineHeightTypes, setLineHeight(), and lineHeightType().

int QTextBlockFormat::lineHeightType() const

This returns the LineHeightType property of the paragraph.

This function was introduced in Qt 4.8.

参见 LineHeightTypes, setLineHeight(), and lineHeight().

bool QTextBlockFormat::nonBreakableLines() const

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

参见 setNonBreakableLines().

PageBreakFlags QTextBlockFormat::pageBreakPolicy() const

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

This function was introduced in Qt 4.2.

参见 setPageBreakPolicy().

qreal QTextBlockFormat::rightMargin() const

Returns the paragraph's right margin.

参见 setRightMargin() and 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(), and setRightMargin().

void QTextBlockFormat::setIndent(int indentation)

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

参见 indent() and QTextDocument::indentWidth().

void QTextBlockFormat::setLeftMargin(qreal margin)

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

参见 leftMargin(), setRightMargin(), setTopMargin(), and 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 enum.

This function was introduced in Qt 4.8.

参见 LineHeightTypes, lineHeight(), and lineHeightType().

void QTextBlockFormat::setNonBreakableLines(bool b)

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

参见 nonBreakableLines().

void QTextBlockFormat::setPageBreakPolicy(PageBreakFlags policy)

Sets the page break policy for the paragraph to policy.

This function was introduced in Qt 4.2.

参见 pageBreakPolicy().

void QTextBlockFormat::setRightMargin(qreal margin)

Sets the paragraph's right margin.

参见 rightMargin(), setLeftMargin(), setTopMargin(), and setBottomMargin().

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

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

This function was introduced in Qt 4.4.

参见 tabPositions().

void QTextBlockFormat::setTextIndent(qreal indent)

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.

参见 textIndent(), setLeftMargin(), setRightMargin(), setTopMargin(), and setBottomMargin().

void QTextBlockFormat::setTopMargin(qreal margin)

Sets the paragraph's top margin.

参见 topMargin(), setBottomMargin(), setLeftMargin(), and setRightMargin().

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

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

This function was introduced in 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() and bottomMargin().