"Application Scenario": Enter a paragraph of text in the edit box, select text with the mouse, modify the font on the toolbar, font size, bold, italic, and other attributes, the selected text changes accordingly.
First,Any text editor program will use Qtextedit as the input text container, in which the editable text entered by Qtextdocument as a carrier, and Qtextblock, Qtextlist, Qtextframe and so on are used to denote elements of qtextdocument, and can also be interpreted as qtextdocument different forms of expression, possibly as strings, paragraphs, lists, tables, or pictures. Each element has its own format, which is described and implemented using classes such as Qtextcharformat, Qtextblockformat, Qtextlistformat, Qtextframeformat, and so on. For example, the Qtextblockformat class corresponds to the Qtextblock class, and the Qtextblock class is used to represent a piece of text, which can generally be understood as a paragraph, but not just a paragraph, and the Qtextblockformat class is used to represent the format of the piece of text, such as an indent value , and four sides of the margin. The division and relationship between the various types can be described:
Second,The Qtextcursor class is a very important and often used class, which is used to represent the cursor in the editing text. This class provides a modification interface to the Qtextdocument document, and all changes to the document format, in the final analysis, are related to the cursor, such as changing the format of the character, which refers to changing the format of the character at the cursor, changing the format of the paragraph, which means changing the format of the paragraph in which the cursor is located, so The Qtextcursor class plays an important role in the document editing class program, and all modifications to Qtextdocument can be implemented through the Qtextcursor class.
" Inheritance Relationship ":
Third,Qtextlistformat is mainly used to describe the format of text sorting, it mainly includes two basic properties, a flavor qtextlistformat::style, which means the text is sorted by which sort, and the other is qtextlistformat::indent, Represents the indented value after sorting. Therefore, to achieve the function of text sorting only need to set the Qtextlistformat of these two properties, and the entire format through the Qtextcursor class to apply to the text.
"References":
- "Instance" QT Text editor (i) http://blog.chinaunix.net/uid-25806493-id-3346294.html
- "Qt 5 Development and examples" (Lu Wenzhou), Fifth: Qt5 main form
Qt5 text Editing