Class: QgsTextDocument

class qgis.core.QgsTextDocument

Bases: sip.wrapper

QgsTextDocument(block: QgsTextBlock) Constructor for a QgsTextDocument consisting of a single text block.

QgsTextDocument(fragment: QgsTextFragment) Constructor for a QgsTextDocument consisting of a single text fragment.

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

Methods

append

Appends a block to the document.

applyCapitalization

Applies a capitalization style to the document’s text.

at

Returns the block at the specified index.

fromHtml

Constructor for QgsTextDocument consisting of a set of HTML formatted lines.

fromPlainText

Constructor for QgsTextDocument consisting of a set of plain text lines.

reserve

Reserves the specified count of blocks for optimised block appending.

size

Returns the number of blocks in the document.

splitLines

Splits lines of text in the document to separate lines, using a specified wrap character (wrapCharacter) or newline characters.

toPlainText

Returns a list of plain text lines of text representing the document.

append(self, block: QgsTextBlock)

Appends a block to the document.

Parameters

block (QgsTextBlock) –

applyCapitalization(self, capitalization: QgsStringUtils.Capitalization)

Applies a capitalization style to the document’s text.

New in version 3.16.

Parameters

capitalization (QgsStringUtils.Capitalization) –

at(self, index: int)QgsTextBlock

Returns the block at the specified index.

Parameters

index (int) –

Return type

QgsTextBlock

fromHtml(lines: Iterable[str])QgsTextDocument

Constructor for QgsTextDocument consisting of a set of HTML formatted lines.

Parameters

lines (Iterable[str]) –

Return type

QgsTextDocument

fromPlainText(lines: Iterable[str])QgsTextDocument

Constructor for QgsTextDocument consisting of a set of plain text lines.

Parameters

lines (Iterable[str]) –

Return type

QgsTextDocument

reserve(self, count: int)

Reserves the specified count of blocks for optimised block appending.

Parameters

count (int) –

size(self) → int

Returns the number of blocks in the document.

Return type

int

splitLines(self, wrapCharacter: str, autoWrapLength: int = 0, useMaxLineLengthWhenAutoWrapping: bool = True)

Splits lines of text in the document to separate lines, using a specified wrap character (wrapCharacter) or newline characters.

The autoWrapLength argument can be used to specify an ideal length of line to automatically wrap text to (automatic wrapping is disabled if autoWrapLength is 0). This automatic wrapping is performed after processing wrapping using wrapCharacter. When auto wrapping is enabled, the useMaxLineLengthWhenAutoWrapping argument controls whether the lines should be wrapped to an ideal maximum of autoWrapLength characters, or if False then the lines are wrapped to an ideal minimum length of autoWrapLength characters.

Parameters
  • wrapCharacter (str) –

  • autoWrapLength (int = 0) –

  • useMaxLineLengthWhenAutoWrapping (bool = True) –

toPlainText(self) → List[str]

Returns a list of plain text lines of text representing the document.

Return type

List[str]