Skip to content

QTextEdit


QTextEdit

QTextEdit is an advanced text editor that provides a rich text display and editing features. It can be used to display and edit formatted text, such as HTML and Markdown.


Signals

  • cursorPositionChanged: Emitted when the cursor position changes.
  • textChanged: Emitted when the text changes.

Methods


Examples


text_edit = QtWidgets.QTextEdit()
text_edit.setHtml("<b>Hello, World!</b>")

print(text_edit.toPlainText())
print(text_edit.toHtml())
Hello, World!
<b>Hello, World!</b>
text_edit.setMarkdown("**Hello, World!**")

print(text_edit.toPlainText())
print(text_edit.Markdown())
Hello, World!
**Hello, World!**

The above code shows how to set the text of a QTextEdit widget using HTML and Markdown and how to get the text in plain text, HTML, and Markdown formats.



append(text)

Append text to the end of the text edit.

Parameters:

Name Type Description Default
text str

The text to append.

required


clear()

Clear the text in the text edit.


copy()

Copiy any selected text to the clipboard.


cut()

Cut any selected text to the clipboard.


isReadOnly()

Check if the text edit is read-only.

Returns:

Name Type Description
bool bool

True if the text edit is read-only, False otherwise.


paste()

Paste text from the clipboard into the text edit.


placeholderText()

Get the placeholder text of the text edit.

Returns:

Name Type Description
str str

The placeholder text of the text edit.


redo()

Redo the last operation.


setFontItalic(b)

Set the italic font style of the text edit. All text added to the text edit after a call with True will be displayed in italic.

Parameters:

Name Type Description Default
b bool

True to set the font style to italic, False otherwise.

required


setFontPointSize(s)

Set the font size of the text edit. All text added to the text edit after a call with a specific size will be displayed with that size.

Parameters:

Name Type Description Default
s float

The font size to set.

required


setFontUnderline(b)

Set the underline font style of the text edit. All text added to the text edit after a call with True will be displayed with an underline.

Parameters:

Name Type Description Default
b bool

True to set the font style to underline, False otherwise.

required


setFontWeight(w)

Set the font weight of the text edit. Font weight is a numerical value that determines the thickness of the characters in the text edit. All text added to the text edit after a call with a specific weight will be displayed with that weight.

Parameters:

Name Type Description Default
w int

The font weight to set.

required


setHtml(text)

Set the text edit contents to the specified HTML text.

Parameters:

Name Type Description Default
text str

The HTML text to set.

required


setMarkdown(markdown)

Set the text edit contents to the specified Markdown text.

Parameters:

Name Type Description Default
markdown str

The Markdown text to set.

required


setPlaceholderText(placeholderText)

Set the placeholder text of the text edit. Placeholder text is grayed out and displayed when the text edit is empty.

Parameters:

Name Type Description Default
placeholderText str

The placeholder text to set.

required


setReadOnly(ro)

Set whether the text edit is read-only. If the text edit is read-only, the user cannot edit the text.

Parameters:

Name Type Description Default
ro bool

True to set the text edit to read-only, False otherwise.

required


setText(text)

Set the contents of the text edit to the specified text. The text is displayed as plain text.

Parameters:

Name Type Description Default
text str

The text to set.

required


toHtml()

Get the text edit contents as HTML text.

Returns:

Name Type Description
str str

The text edit contents as HTML text.


toMarkdown()

Get the text edit contents as Markdown text.

Returns:

Name Type Description
str str

The text edit contents as Markdown text.


toPlainText()

Get the text edit contents as plain text. For example if the text edit contains the HTML text <b>bold</b>, the returned text will be bold.

Returns:

Name Type Description
str str

The text edit contents as plain text.


undo()

Undo the last operation in the text edit.


zoomIn(r)

Zoom in the text edit by the specified range.

Parameters:

Name Type Description Default
r int

The range to zoom in by.

required


zoomOut(r)

Zoom out the text edit by the specified range.

Parameters:

Name Type Description Default
r int

The range to zoom out by.

required