![]() |
Qt 6.x
The Qt SDK
|
\reentrant More...
#include <qtextformat.h>
Public Member Functions | |
QTextBlockFormat () | |
Constructs a new QTextBlockFormat. | |
bool | isValid () const |
Returns true if this block format is valid; otherwise returns false. | |
void | setAlignment (Qt::Alignment alignment) |
Sets the paragraph's alignment. | |
Qt::Alignment | alignment () const |
Returns the paragraph's alignment. | |
void | setTopMargin (qreal margin) |
Sets the paragraph's top margin. | |
qreal | topMargin () const |
Returns the paragraph's top margin. | |
void | setBottomMargin (qreal margin) |
Sets the paragraph's bottom margin. | |
qreal | bottomMargin () const |
Returns the paragraph's bottom margin. | |
void | setLeftMargin (qreal margin) |
Sets the paragraph's left margin. | |
qreal | leftMargin () const |
Returns the paragraph's left margin. | |
void | setRightMargin (qreal margin) |
Sets the paragraph's right margin. | |
qreal | rightMargin () const |
Returns the paragraph's right margin. | |
void | setTextIndent (qreal aindent) |
Sets the indent for the first line in the block. | |
qreal | textIndent () const |
Returns the paragraph's text indent. | |
void | setIndent (int indent) |
Sets the paragraph's indentation. | |
int | indent () const |
Returns the paragraph's indent. | |
void | setHeadingLevel (int alevel) |
int | headingLevel () const |
void | setLineHeight (qreal height, int heightType) |
qreal | lineHeight (qreal scriptLineHeight, qreal scaling) const |
qreal | lineHeight () const |
int | lineHeightType () const |
void | setNonBreakableLines (bool b) |
If b is true, the lines in the paragraph are treated as non-breakable; otherwise they are breakable. | |
bool | nonBreakableLines () const |
Returns true if the lines in the paragraph are non-breakable; otherwise returns false . | |
void | setPageBreakPolicy (PageBreakFlags flags) |
PageBreakFlags | pageBreakPolicy () const |
void | setTabPositions (const QList< QTextOption::Tab > &tabs) |
QList< QTextOption::Tab > | tabPositions () const |
void | setMarker (MarkerType marker) |
MarkerType | marker () const |
![]() | |
QTextFormat () | |
Creates a new text format with an InvalidFormat . | |
QTextFormat (int type) | |
Creates a new text format of the given type. | |
QTextFormat (const QTextFormat &rhs) | |
Creates a new text format with the same attributes as the other text format. | |
QTextFormat & | operator= (const QTextFormat &rhs) |
Assigns the other text format to this text format, and returns a reference to this text format. | |
~QTextFormat () | |
Destroys this text format. | |
void | swap (QTextFormat &other) |
void | merge (const QTextFormat &other) |
Merges the other format with this format; where there are conflicts the other format takes precedence. | |
bool | isValid () const |
Returns true if the format is valid (i.e. | |
bool | isEmpty () const |
int | type () const |
Returns the type of this format. | |
int | objectIndex () const |
Returns the index of the format object, or -1 if the format object is invalid. | |
void | setObjectIndex (int object) |
Sets the format object's object index. | |
QVariant | property (int propertyId) const |
Returns the property specified by the given propertyId. | |
void | setProperty (int propertyId, const QVariant &value) |
Sets the property specified by the propertyId to the given value. | |
void | clearProperty (int propertyId) |
Clears the value of the property given by propertyId. | |
bool | hasProperty (int propertyId) const |
Returns true if the text format has a property with the given propertyId; otherwise returns false . | |
bool | boolProperty (int propertyId) const |
Returns the value of the property specified by propertyId. | |
int | intProperty (int propertyId) const |
Returns the value of the property specified by propertyId. | |
qreal | doubleProperty (int propertyId) const |
Returns the value of the property specified by propertyId. | |
QString | stringProperty (int propertyId) const |
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QString type, an empty string is returned instead. | |
QColor | colorProperty (int propertyId) const |
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QColor type, an invalid color is returned instead. | |
QPen | penProperty (int propertyId) const |
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QPen type, Qt::NoPen is returned instead. | |
QBrush | brushProperty (int propertyId) const |
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QBrush type, Qt::NoBrush is returned instead. | |
QTextLength | lengthProperty (int propertyId) const |
Returns the value of the property given by propertyId. | |
QList< QTextLength > | lengthVectorProperty (int propertyId) const |
Returns the value of the property given by propertyId. | |
void | setProperty (int propertyId, const QList< QTextLength > &lengths) |
Sets the value of the property given by propertyId to value. | |
QMap< int, QVariant > | properties () const |
Returns a map with all properties of this text format. | |
int | propertyCount () const |
void | setObjectType (int type) |
Sets the text format's object type to type. | |
int | objectType () const |
Returns the text format's object type. | |
bool | isCharFormat () const |
Returns true if this text format is a CharFormat ; otherwise returns false . | |
bool | isBlockFormat () const |
Returns true if this text format is a BlockFormat ; otherwise returns false . | |
bool | isListFormat () const |
Returns true if this text format is a ListFormat ; otherwise returns false . | |
bool | isFrameFormat () const |
Returns true if this text format is a FrameFormat ; otherwise returns false . | |
bool | isImageFormat () const |
Returns true if this text format is an image format; otherwise returns false . | |
bool | isTableFormat () const |
Returns true if this text format is a TableFormat ; otherwise returns false . | |
bool | isTableCellFormat () const |
QTextBlockFormat | toBlockFormat () const |
Returns this format as a block format. | |
QTextCharFormat | toCharFormat () const |
Returns this format as a character format. | |
QTextListFormat | toListFormat () const |
Returns this format as a list format. | |
QTextTableFormat | toTableFormat () const |
Returns this format as a table format. | |
QTextFrameFormat | toFrameFormat () const |
Returns this format as a frame format. | |
QTextImageFormat | toImageFormat () const |
Returns this format as an image format. | |
QTextTableCellFormat | toTableCellFormat () const |
bool | operator== (const QTextFormat &rhs) const |
Returns true if this text format is the same as the other text format. | |
bool | operator!= (const QTextFormat &rhs) const |
Returns true if this text format is different from the other text format. | |
operator QVariant () const | |
Returns the text format as a QVariant. | |
void | setLayoutDirection (Qt::LayoutDirection direction) |
Sets the document's layout direction to the specified direction. | |
Qt::LayoutDirection | layoutDirection () const |
Returns the document's layout direction. | |
void | setBackground (const QBrush &brush) |
Sets the brush use to paint the document's background to the brush specified. | |
QBrush | background () const |
Returns the brush used to paint the document's background. | |
void | clearBackground () |
Clears the brush used to paint the document's background. | |
void | setForeground (const QBrush &brush) |
Sets the foreground brush to the specified brush. | |
QBrush | foreground () const |
Returns the brush used to render foreground details, such as text, frame outlines, and table borders. | |
void | clearForeground () |
Clears the brush used to paint the document's foreground. | |
Protected Member Functions | |
QTextBlockFormat (const QTextFormat &fmt) | |
Friends | |
class | QTextFormat |
Q_GUI_EXPORT QDataStream & | operator<< (QDataStream &, const QTextBlockFormat &) |
Q_GUI_EXPORT QDataStream & | operator>> (QDataStream &, QTextBlockFormat &) |
\reentrant
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument. \inmodule QtGui
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 \l{QTextFormat::setBackground()}{setBackground()}, and other aspects of the text's appearance can be customized by using the \l{QTextFormat::setProperty()}{setProperty()} function with the OutlinePen
, ForegroundBrush
, and BackgroundBrush
\l{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.
Definition at line 605 of file qtextformat.h.
This enum describes the various types of line spacing support paragraphs can have.
\value SingleHeight This is the default line height: single spacing. \value ProportionalHeight This sets the spacing proportional to the line (in percentage). For example, set to 200 for double spacing. \value FixedHeight This sets the line height to a fixed line height (in pixels). \value MinimumHeight This sets the minimum line height (in pixels). \value LineDistanceHeight This adds the specified height between lines (in pixels).
Enumerator | |
---|---|
SingleHeight | |
ProportionalHeight | |
FixedHeight | |
MinimumHeight | |
LineDistanceHeight |
Definition at line 608 of file qtextformat.h.
|
strong |
This enum describes the types of markers a list item can have. If a list item (a paragraph for which \l QTextBlock::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 \l QTextListFormat::style() for the entire list.
\value NoMarker This is the default: the list item's bullet will be shown. \value Unchecked Instead of the list item's bullet, an unchecked checkbox will be shown. \value 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.
Enumerator | |
---|---|
NoMarker | |
Unchecked | |
Checked |
Definition at line 616 of file qtextformat.h.
QTextBlockFormat::QTextBlockFormat | ( | ) |
Constructs a new QTextBlockFormat.
Definition at line 2218 of file qtextformat.cpp.
|
explicitprotected |
Creates a new block format with the same attributes as the given text format.
Definition at line 2227 of file qtextformat.cpp.
|
inline |
Returns the paragraph's alignment.
Definition at line 627 of file qtextformat.h.
References Qt::AlignLeft.
Referenced by QTextHtmlParser::applyAttributes(), and QTextDocumentLayoutPrivate::layoutBlock().
|
inline |
Returns the paragraph's bottom margin.
Definition at line 637 of file qtextformat.h.
Referenced by QTextMarkdownImporter::cbText(), QTextDocumentLayoutPrivate::layoutBlock(), and QTextDocumentLayoutPrivate::layoutFlow().
|
inline |
Returns the paragraph's heading level if it is a heading, or 0 if not.
Definition at line 661 of file qtextformat.h.
Referenced by QTextMarkdownWriter::writeBlock().
|
inline |
Returns the paragraph's indent.
Definition at line 656 of file qtextformat.h.
Referenced by QTextDocumentLayoutPrivate::blockIndent(), QAbstractTextDocumentLayout::blockWithMarkerAt(), QTextMarkdownImporter::cbText(), QTextEditPrivate::createAutoBulletList(), QWidgetTextControlPrivate::createAutoBulletList(), QWidgetTextControlPrivate::indent(), QWidgetTextControlPrivate::keyPressEvent(), QQuickTextControlPrivate::keyPressEvent(), QPlainTextEdit::keyReleaseEvent(), QTextEdit::keyReleaseEvent(), QWidgetTextControlPrivate::outdent(), QTextMarkdownWriter::writeBlock(), and QTextMarkdownWriter::writeFrame().
|
inline |
Returns true
if this block format is valid; otherwise returns false.
Definition at line 624 of file qtextformat.h.
Referenced by QTextDocumentPrivate::setBlockFormat().
|
inline |
Returns the paragraph's left margin.
Definition at line 642 of file qtextformat.h.
Referenced by QAbstractTextDocumentLayout::blockWithMarkerAt(), QTextMarkdownImporter::cbText(), and QTextDocumentLayoutPrivate::layoutBlock().
|
inline |
This returns the LineHeight property for the paragraph.
Definition at line 667 of file qtextformat.h.
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.
Definition at line 705 of file qtextformat.h.
References QTextFormat::doubleProperty(), FixedHeight, QTextFormat::intProperty(), LineDistanceHeight, QTextFormat::LineHeight, QTextFormat::LineHeightType, MinimumHeight, ProportionalHeight, qMax(), and SingleHeight.
Referenced by getLineHeightParams().
|
inline |
This returns the LineHeightType property of the paragraph.
Definition at line 669 of file qtextformat.h.
Referenced by getLineHeightParams().
|
inline |
Returns the paragraph's marker if one has been set, or NoMarker
if not.
Definition at line 687 of file qtextformat.h.
Referenced by QQuickTextNodeEngine::addTextBlock(), QAbstractTextDocumentLayout::blockWithMarkerAt(), QTextDocumentLayoutPrivate::drawListItem(), QQuickTextControlPrivate::hoverEvent(), and QTextMarkdownWriter::writeBlock().
|
inline |
Returns true
if the lines in the paragraph are non-breakable; otherwise returns false
.
Definition at line 674 of file qtextformat.h.
Referenced by QTextDocumentLayoutPrivate::layoutBlock(), and QTextMarkdownWriter::writeBlock().
|
inline |
Returns the currently set page break policy for the paragraph. The default is QTextFormat::PageBreak_Auto.
Definition at line 679 of file qtextformat.h.
Referenced by QTextHtmlImporter::import(), and QTextDocumentLayoutPrivate::layoutFlow().
|
inline |
Returns the paragraph's right margin.
Definition at line 647 of file qtextformat.h.
Referenced by QTextMarkdownImporter::cbText(), and QTextDocumentLayoutPrivate::layoutBlock().
|
inline |
Sets the paragraph's alignment.
Definition at line 699 of file qtextformat.h.
References QTextFormat::BlockAlignment, and setProperty().
Referenced by QTextHtmlParser::applyAttributes(), QTextMarkdownImporter::cbEnterBlock(), QTextHtmlParserNode::initializeProperties(), main(), and main_textblock_formats().
Sets the paragraph's bottom margin.
Definition at line 635 of file qtextformat.h.
References setProperty().
Referenced by main_textblock_formats().
|
inline |
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).
Definition at line 659 of file qtextformat.h.
References setProperty().
Referenced by QTextMarkdownImporter::cbEnterBlock().
|
inline |
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.
Definition at line 702 of file qtextformat.h.
References QTextFormat::BlockIndent, and QTextFormat::setProperty().
Referenced by QTextMarkdownImporter::cbText(), QTextEditPrivate::createAutoBulletList(), QWidgetTextControlPrivate::createAutoBulletList(), QTextHtmlImporter::import(), QWidgetTextControlPrivate::indent(), QWidgetTextControlPrivate::keyPressEvent(), QQuickTextControlPrivate::keyPressEvent(), QPlainTextEdit::keyReleaseEvent(), QTextEdit::keyReleaseEvent(), and QWidgetTextControlPrivate::outdent().
Sets the paragraph's left margin.
Indentation can be applied separately with setIndent().
Definition at line 640 of file qtextformat.h.
References setProperty().
Referenced by main_textblock_formats().
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.
Definition at line 664 of file qtextformat.h.
References setProperty().
Referenced by QQuickTextPrivate::updateLayout().
|
inline |
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
.
Definition at line 685 of file qtextformat.h.
References setProperty().
Referenced by QTextHtmlParser::applyAttributes().
|
inline |
If b is true, the lines in the paragraph are treated as non-breakable; otherwise they are breakable.
Definition at line 672 of file qtextformat.h.
References setProperty().
|
inline |
Sets the page break policy for the paragraph to policy.
Definition at line 677 of file qtextformat.h.
References setProperty().
Referenced by QTextHtmlImporter::import().
Sets the paragraph's right margin.
Definition at line 645 of file qtextformat.h.
References setProperty().
Referenced by main_textblock_formats().
void QTextBlockFormat::setTabPositions | ( | const QList< QTextOption::Tab > & | tabs | ) |
Definition at line 2239 of file qtextformat.cpp.
References QList< T >::append(), QList< T >::constBegin(), QList< T >::constEnd(), iter, list, QList< T >::reserve(), QTextFormat::setProperty(), QList< T >::size(), and QTextFormat::TabPositions.
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.
Definition at line 650 of file qtextformat.h.
References setProperty().
Referenced by main_textblock_formats().
Sets the paragraph's top margin.
Definition at line 630 of file qtextformat.h.
References setProperty().
Referenced by main_textblock_formats().
QList< QTextOption::Tab > QTextBlockFormat::tabPositions | ( | ) | const |
Definition at line 2259 of file qtextformat.cpp.
References QList< T >::append(), QList< T >::begin(), QList< T >::end(), QVariant::isNull(), iter, property, QList< T >::reserve(), QList< T >::size(), QTextFormat::TabPositions, and variant.
Referenced by QTextDocumentLayoutPrivate::layoutBlock().
|
inline |
Returns the paragraph's text indent.
Definition at line 652 of file qtextformat.h.
Referenced by QAbstractTextDocumentLayout::blockWithMarkerAt(), QTextMarkdownImporter::cbText(), and QTextDocumentLayoutPrivate::layoutBlock().
|
inline |
Returns the paragraph's top margin.
Definition at line 632 of file qtextformat.h.
Referenced by QTextMarkdownImporter::cbText(), QTextDocumentLayoutPrivate::hitTest(), QTextDocumentLayoutPrivate::layoutBlock(), and QTextDocumentLayoutPrivate::layoutFlow().
|
friend |
Definition at line 474 of file qtextformat.cpp.
|
friend |
Definition at line 479 of file qtextformat.cpp.
|
friend |
Definition at line 692 of file qtextformat.h.