Qt rich text editor - is there an already-made one? [closed]
Asked Answered
H

4

11

I need a rich text editor for Qt. I've been thinking about using QTextEdit since it's a rich text edit, but I need two things that aren't present in that widget:

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

  • The user should be able to drag'n'drop or add by searching for it an image. Now if I try to copy-and-paste an image onto my QTextEdit I just see this

enter image description here

How should I do for each one of my needs?

Hauptmann answered 24/7, 2012 at 12:14 Comment(0)
B
4

1) Have a look at this official example, it should give you a rich text editor that is able to change the text, with a 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 a text edit (either 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 all you need and even more:

https://github.com/Anchakor/MRichTextEditor


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

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

Bartholomew answered 30/11, 2015 at 10:17 Comment(2)
First link doesn't work anymoreMarinelli
@NedimMemišević Thank you for the heads up, Qt removed the example, unfortunately, I don't know how to fix that.Bartholomew
A
1

wwWidgets has RichTextEditor -> http://www.wysota.eu.org/wwwidgets/doc/html/qwwrichtextedit.html

Ameline answered 24/7, 2012 at 12:59 Comment(2)
Neither constructive nor helpful.Stairway
This is basically the same as QTextEdit with easier accessors.Lizettelizotte
P
1

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

Platonism answered 3/4, 2014 at 19:49 Comment(0)
L
0

Another idea might be to use WebKit to make this widget. See: https://www.qt.io/blog/2009/03/12/wysiwyg-html-editor

Note that the git repository linked there moved to this URL: https://code.qt.io/cgit/%7Bnon-gerrit%7D/qt-labs/graphics-dojo.git/tree/?id=8000ca3b229344ed2ba2ae81ed5ebaee86e9d63a

Lizettelizotte answered 25/9, 2013 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.