Class: QgsTextDocument¶
Represents a document consisting of one or more QgsTextBlock
objects.
Warning
This API is not considered stable and may change in future QGIS versions.
Added in version 3.14.
- class qgis.core.QgsTextDocument[source]¶
Bases:
object- __init__()
- __init__(other: QgsTextDocument)
- Parameters:
other (QgsTextDocument)
- __init__(block: QgsTextBlock)
Constructor for a QgsTextDocument consisting of a single text
block.- Parameters:
block (QgsTextBlock)
- __init__(fragment: QgsTextFragment)
Constructor for a QgsTextDocument consisting of a single text
fragment.- Parameters:
fragment (QgsTextFragment)
- append(self, block: QgsTextBlock)[source]¶
Appends a
blockto the document.- Parameters:
block (QgsTextBlock)
- applyCapitalization(self, capitalization: Qgis.Capitalization)[source]¶
Applies a
capitalizationstyle to the document’s text.Added in version 3.16.
- Parameters:
capitalization (Qgis.Capitalization)
- at(self, index: int) QgsTextBlock¶
Returns the block at the specified
index.- Raises:
KeyError – if no block exists at the specified index.
- Parameters:
index (int)
- Return type:
- static fromHtml(lines: Iterable[str | None]) QgsTextDocument[source]¶
Constructor for
QgsTextDocumentconsisting of a set of HTML formattedlines.If the HTML contains tab characters they will be appended as separate text fragments within the document, consisting of just the tab character.
- Parameters:
lines (Iterable[Optional[str]])
- Return type:
- static fromPlainText(lines: Iterable[str | None]) QgsTextDocument[source]¶
Constructor for
QgsTextDocumentconsisting of a set of plain textlines.If any line contains tab characters they will be appended as separate text fragments within the document, consisting of just the tab character.
- Parameters:
lines (Iterable[Optional[str]])
- Return type:
- static fromTextAndFormat(lines: Iterable[str | None], format: QgsTextFormat) QgsTextDocument[source]¶
Constructor for
QgsTextDocumentconsisting of a set oflines, respecting settings from a textformat.This method will determine from the text
formatwhether the lines should be treated as HTML or plain text.Added in version 3.40.
- Parameters:
lines (Iterable[Optional[str]])
format (QgsTextFormat)
- Return type:
- hasBackgrounds(self) bool[source]¶
Returns
Trueif any blocks or fragments in the document have background brushes set.Added in version 3.42.
- Return type:
bool
- insert(self, index: int, block: QgsTextBlock)[source]¶
Inserts a
blockinto the document, at the specified index.- Raises:
IndexError – if no block exists at the specified index.
Added in version 3.40.
- Parameters:
index (int)
block (QgsTextBlock)
- reserve(self, count: int)[source]¶
Reserves the specified
countof blocks for optimised block appending.- Parameters:
count (int)
- splitLines(self, wrapCharacter: str | None, autoWrapLength: int = 0, useMaxLineLengthWhenAutoWrapping: bool = True)[source]¶
Splits lines of text in the document to separate lines, using a specified wrap character (
wrapCharacter) or newline characters.The
autoWrapLengthargument can be used to specify an ideal length of line to automatically wrap text to (automatic wrapping is disabled ifautoWrapLengthis 0). This automatic wrapping is performed after processing wrapping usingwrapCharacter. When auto wrapping is enabled, theuseMaxLineLengthWhenAutoWrappingargument controls whether the lines should be wrapped to an ideal maximum ofautoWrapLengthcharacters, or ifFalsethen the lines are wrapped to an ideal minimum length ofautoWrapLengthcharacters.- Parameters:
wrapCharacter (Optional[str])
autoWrapLength (int = 0)
useMaxLineLengthWhenAutoWrapping (bool = True)