MS Word like behavior with QTextEdit
-
Hello,
I want to achieve MS Word like behavior with QTextEdit - have text with images, that can be saved to a single file.
I've seen several discussions about that, but still can`t figure out how to do this without overcompicating my solution.If I add image like this:
QTextCursor cursor = textCursor(); QTextImageFormat image_format; image_format.setName(path); cursor.beginEditBlock(); cursor.insertImage(image_format); cursor.endEditBlock();
I can use toHtml() to get HTML text with links to images. However, all these images are just references to some files.
I can parse my HTML before saving and save all these files separately. But I don`t quite understand how to make QTextEdit use loaded images. -
Hello,
I want to achieve MS Word like behavior with QTextEdit - have text with images, that can be saved to a single file.
I've seen several discussions about that, but still can`t figure out how to do this without overcompicating my solution.If I add image like this:
QTextCursor cursor = textCursor(); QTextImageFormat image_format; image_format.setName(path); cursor.beginEditBlock(); cursor.insertImage(image_format); cursor.endEditBlock();
I can use toHtml() to get HTML text with links to images. However, all these images are just references to some files.
I can parse my HTML before saving and save all these files separately. But I don`t quite understand how to make QTextEdit use loaded images.@bidjiz said in MS Word like behavior with QTextEdit:
I want to achieve MS Word like behavior with QTextEdit - have text with images, that can be saved to a single file.
I believe this will be a vain effort, or at least pretty difficult. MS Word is a full-featured word processor,
QTextEdit
is not. If you look at a saved.docx
file you will find it is actually a Zip file, containing other files, presumably including any images.So far as I know, even if a
QTextImageFormat
creates an embedded image in theQTextDocument
(I don't know whether it does) you cannot serialize aQTextDocument
yourself, and even if you useQTextDocumentWriter
you can get HTML or ODF out but I don't think those embed images? Try them to see? -
@bidjiz said in MS Word like behavior with QTextEdit:
I want to achieve MS Word like behavior with QTextEdit - have text with images, that can be saved to a single file.
I believe this will be a vain effort, or at least pretty difficult. MS Word is a full-featured word processor,
QTextEdit
is not. If you look at a saved.docx
file you will find it is actually a Zip file, containing other files, presumably including any images.So far as I know, even if a
QTextImageFormat
creates an embedded image in theQTextDocument
(I don't know whether it does) you cannot serialize aQTextDocument
yourself, and even if you useQTextDocumentWriter
you can get HTML or ODF out but I don't think those embed images? Try them to see?@JonB Thank you for the answer. I don't want to write my own MS Word, so it's not nessesary to serialize whole QTextDocument. I would be quite happy if I will be able to pass loaded images to QTextDocument. But it seems that it needs valid images from the disk. Sure I can create them in some temporary folder, but it does not look like a good idea.