QTextDocument Frames and Rendering

  • I have read all the qt documentation on QTextEdit, QPlaintTextEdit, QTextDocument, QTextBlock, QTextCursor, QSyntaxHighlighter, etc. The documentation is strong on how to do something, but like nearly all documentation, it does not cover why you would do it; that is left to examples. I have questions regarding frames and how the renderers of QTextEdit andQPlaintTextEdit handle frames and rich-text.

    It appears to me that frames are used in both editors when it is necessary to change the formatting of some text blocks, e.g., say the case where a long citation is inserted, with indention on both sides and an italic font. Is there some document that goes into more detail on the use of frames in QPlainText documents?

    The second question relates to the rendering of documents. Because both QTextEdit and QPlainTextEdit are based on the QTextDocument and QTextCursor can insert both frames and rich-text, it would seem that I could insert frames and rich-text into a plain text document. Does the rendering code show the rich-text as plain text and ignore any frame that it cannot render?

  • Lifetime Qt Champion


    Can you show an example of what you would like to achieve ?

  • @SGaist There is nothing in particular, I am just trying to understand the limitations. For example, it would seem that the only "frames" allowed in that QTextDcoument are text blocks, which can contain plain or rich-text, tables, lists and images. The QPlainTextEditor can only handle text blocks in the form of QStrings. The citation example was one I surmised could be handled by the formatting capability of the frame. The QTextEditor has all the capabilities of the QPlainTextEdit and adds rich-text. I was just wondering if I was missing something.

  • Lifetime Qt Champion

    QPlainTextEdit is optimised for "not-fancy" text rendering while QTextEdit is for rich text.

  • @SGaist I want to have plan text and display equations--in standard mathematical form.

  • @ofmrew Allow me to expand on my response. If you are familiar with LaTeX, then you will understand my usage of inline and display math. I want to develop an editor that will combine plain text with LaTeX statements that will display when the source is compiled. The concept of using a frame to create an area, both within a text line and as a separate paragraph, where something other than plain text, and equation, is displayed is what I want, but I see no way of creating and displaying the contents of my frame. If creating my own frame and painter is not possible, then I will build it from scratch using QWidget and QPainter, but I hope I am missing something.

  • Lifetime Qt Champion

    So you would like to implement some sort of WYSIWYG LaTeX editor ?

  • @SGaist It is like that but more. LaTeX is for typesetting documents, especially those with mathematical expressions. I want the text and the subset of LaTeX to be compiled into executable code. Purpose: to provide a visual aid to the equations being used and not having to relying on interpreting the butchered programming language code--this would not only help the programmer, but all that follow doing maintenance.

    QPlaintTextEdit and QTextEdit have many features that I would like to use. Right now I am exploring whether subclassing QFrame and QCursor will do what I want.

  • @SGaist I did some research and subclassing is a dead end. It appears that QTextEdit keeps a QTextDocument as a property, but QPlaintTextEdit keeps only a QString--I assume that the QTextDocument is created only when requested.

  • Lifetime Qt Champion

    A quick look at the sources of QPlaintTextEdit shows that it uses a QTextDocument but with a custom QAbstractTextDocumentLayout.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.