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

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]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

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