PyQt6-QTextEdit study notes

I. Overview

Basic usage of QTextEdit control in technical PyQt6.

QTextEdit is an advanced WYSIWYG viewer/editor that supports rich text formatting using html style tags or Markdown format. It is optimized to handle large documents and respond quickly to user input.

QTextEdit works on paragraphs and characters. A paragraph is a formatted string that is wrapped to fit the width of the widget. By default, when reading plain text, a newline character represents a paragraph. A document consists of zero or more paragraphs. Words in a paragraph follow the alignment of the paragraph. Paragraphs are separated by hard line breaks. Each character in a paragraph has its own properties, such as font and color.

QTextEdit can display images, lists and tables. Scroll bars appear if the text is too large to be viewed in the text editor's viewport. The text editor can load plain text and rich text files. Rich text can be described using a subset of HTML 4 tags; see the Supported HTML Subsets page for more information.

If you only need to display a small piece of rich text, use QLabel.

Rich text support in Qt aims to provide a fast, portable and efficient way of adding reasonable online help facilities to applications and to provide a basis for rich text editors. If you find HTML support insufficient for your needs, you might consider using Qt WebKit, which provides a fully functional web browser widget.

The shape of the mouse cursor on QTextEdit defaults to IBeamCursor. It can be changed through the cursor property of viewport().

2. Common methods

1. Set the file display setDocument( QTextDocument )

Settings file display

2. Set Html display setHtml(str)

3. Set Markdown display setMarkdown(str)

4. Display plain text setPlainText(str)

5. Display text setText(str)

Guess you like

Origin blog.csdn.net/u010839204/article/details/128921162