Qt rich text editor - is there anything already done?

I need a text editor for Qt. I was thinking about using QTextEdit as it is text editing, but I need two things that are not in this widget:

  • The user should be able to change the text color, text font, underline, bold, italic text, so I need something like a text editor toolbar with these controls (do I need to encode them myself?)

  • The user must be able to drag and drop while searching for this image. Now, if I try to copy and paste the image into my QTextEdit, I just see this

enter image description here

How do I do for each of my needs?

+6
source share
4 answers

1) Look at this official example, it should provide you with a rich text editor that can change the text using the toolbar:

http://doc.qt.io/qt-5/qtwidgets-richtext-textedit-textedit-cpp.html

To drag and drop images, I'm afraid you will have to subclass text editing (QTextEdit or QTextBrowser) and implement these two methods:

void QTextEdit::dropImage(QImage const& p_image, QString const& p_format) void QTextEdit::insertFromMimeData(const QMimeData* p_source) 

2) Here is a GitHub project that implements everything you need, and even more:

https://github.com/Anchakor/MRichTextEditor


Finally, if you want to understand how text editors work, here is the documentation:

http://doc.qt.io/qt-5/richtext.html

+2
source

You can use this editor extracted from Deko CRM: http://www.hobrasoft.cz/en/blog/bravenec/qt-rich-text-editor

+1
source

Another idea would be to use WebKit to create this widget. See: http://blog.qt.digia.com/blog/2009/03/12/wysiwyg-html-editor/

Note that the associated git repository has moved to this URL: https://qt.gitorious.org/qt-labs/graphics-dojo/source/8000ca3b229344ed2ba2ae81ed5ebaee86e9d63a :

0
source
-1
source

Source: https://habr.com/ru/post/921201/


All Articles