Class: QgsRichTextEditor

A widget for editing rich text documents, with support for user controlled formatting of text and insertion of hyperlinks and images.

QgsRichTextEditor provides a reusable widget for allowing users to edit rich text documents, and retrieving and setting the documents via HTML formatted strings.

Added in version 3.20.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsRichTextEditor

Base classes

QWidget

QObject

QPaintDevice

Enums

Mode

Widget modes.

Methods

clearSource

Clears the current text from the widget.

document

Returns a reference to the QTextDocument shown in the widget.

mode

Returns the widget's mode, which defines which formatting options are exposed in the widget.

setMode

Sets the widget's mode, which defines which formatting options are exposed in the widget.

setText

Sets the text to show in the widget.

setTextCursor

Sets the current text cursor.

textCursor

Returns a reference to the text cursor.

textEdit

Returns the widget's QTextEditor control.

toHtml

Returns the widget's content as a HTML string.

toPlainText

Returns the widget's content as a plain text string.

Signals

textChanged

Emitted when the text contents are changed.

class qgis.gui.QgsRichTextEditor[source]

Bases: QWidget

__init__(parent: QWidget | None = None)

Constructor for QgsRichTextEditor, with the specified parent widget.

Parameters:

parent (Optional[QWidget] = None)

class Mode(*values)

Bases: IntEnum

Widget modes.

Added in version 3.40.

  • QTextDocument: Default mode, exposes the Qt supported HTML/CSS subset

  • QgsTextRenderer: QGIS text renderer mode, exposes the HTML/CSS subset supported by the QgsTextRenderer class

  • PlainText: Plain text mode

PlainText = 2
QTextDocument = 0
QgsTextRenderer = 1
clearSource(self)[source]

Clears the current text from the widget.

document(self) QTextDocument | None[source]

Returns a reference to the QTextDocument shown in the widget.

Return type:

Optional[QTextDocument]

mode(self) QgsRichTextEditor.Mode[source]

Returns the widget’s mode, which defines which formatting options are exposed in the widget.

See also

setMode()

Added in version 3.40.

Return type:

QgsRichTextEditor.Mode

setMode(self, mode: QgsRichTextEditor.Mode)[source]

Sets the widget’s mode, which defines which formatting options are exposed in the widget.

See also

mode()

Added in version 3.40.

Parameters:

mode (QgsRichTextEditor.Mode)

setText(self, text: str | None)[source]

Sets the text to show in the widget.

The text can either be a plain text string or a HTML document.

Parameters:

text (Optional[str])

setTextCursor(self, cursor: QTextCursor)[source]

Sets the current text cursor.

See also

textCursor()

Parameters:

cursor (QTextCursor)

signal textChanged[source]

Emitted when the text contents are changed.

Added in version 3.26.

textCursor(self) QTextCursor[source]

Returns a reference to the text cursor.

See also

setTextCursor()

Return type:

QTextCursor

textEdit(self) QTextEdit | None[source]

Returns the widget’s QTextEditor control.

Added in version 3.40.

Return type:

Optional[QTextEdit]

toHtml(self) str[source]

Returns the widget’s content as a HTML string.

See also

toPlainText()

Return type:

str

toPlainText(self) str[source]

Returns the widget’s content as a plain text string.

See also

toHtml()

Return type:

str