Several ways of placing an image in a QTextEdit

Viewed 15978

I think this is a very simple question, but when I copy an image I can't paste it in a QTextEdit? Paste is inactive! Also I would like to know how to drag-and-drop a picture.

BTW I use the following code in order to insert a picture into a QTextEdit:

QTextEdit *textEditor = new QTextEdit(0);
QTextDocumentFragment fragment;
fragment = QTextDocumentFragment::fromHtml("<img src='C:\\aaa.jpg'>");
textEditor->textCursor().insertFragment(fragment);
textEditor->setVisible(true);

Is it recommended? How do you do this operation?

2 Answers

For Narek's the second way, if you use

Url Uri ( QString ( "file://%1" ).arg ( file ) );

when you open the .html file the image will not be shown correctly. So just modify it to:

QUrl Uri(QString("%1").arg(file));
Related