I am trying to be able to drag and drop images from files into a QTextEdit and display them in it.
I subclassed QTextEdit reimplemented dropEvent and it sort of works, the right url of image is used, when I open the resulting document(saved from the QTextEdit in html) in firefox the image gets displayed, but in my QTextEdit only an image icon is displayed, not the image.
Also after I drag and drop the image the cursor stops blinking.

Here is the code:

Qt Code:
  1. void CQTextEdit::dragEnterEvent(QDragEnterEvent *event)
  2. {
  3. event->acceptProposedAction();
  4. }
  5.  
  6. void CQTextEdit::dropEvent(QDropEvent *e)
  7. {
  8. if (e->mimeData()->hasFormat("text/uri-list"))
  9. {
  10. journalImage = &qvariant_cast<QImage>(e->mimeData()->imageData());
  11. QTextCursor cursor = this->textCursor();
  12. QTextDocument *document = this->document();
  13. cursor.movePosition(QTextCursor::Right,QTextCursor::MoveAnchor,this->toPlainText().size());
  14. document->addResource(QTextDocument::ImageResource,e->mimeData()->urls()[0],journalImage);
  15. cursor.insertImage(e->mimeData()->urls()[0].toString());
  16. this->setHtml(this->toHtml());
  17.  
  18. }
  19. else QTextEdit::dropEvent(e);
  20. }
To copy to clipboard, switch view to plain text mode 

journalImage is a pointer to a QImage.
Part of the code was inspired from the docs:
http://doc.trolltech.com/4.3/qtextedit.html
Which I also tried to use, but with not too much luck.
Can anyone help me ?