I'm insert Images via QFileDialog into my QTextEdit Class.
TextEditor
::TextEditor ( QWidget *parent, HJcmsSettings
*cfg, HJcmsIconTheme
*theme
) , m_HJcmsSettings ( cfg )
, m_HJcmsIconTheme ( theme )
{
m_HtmlEditorActions = new HtmlEditorActions ( this, theme );
m_QTextDocument = document();
m_QTextDocument->setHtml ( "<p>New Document</p>" );
.......
}
void TextEditor
::InsertImage ( const QString &file
) {
imageFormat.setWidth( image.width() );
imageFormat.setHeight( image.height() );
imageFormat.setName( Uri.toString() );
cursor.insertImage(imageFormat);
setLineWrapColumnOrWidth( lineWrapColumnOrWidth() );
}
TextEditor::TextEditor ( QWidget *parent, HJcmsSettings *cfg, HJcmsIconTheme *theme )
: QTextEdit ( parent )
, m_HJcmsSettings ( cfg )
, m_HJcmsIconTheme ( theme )
{
m_HtmlEditorActions = new HtmlEditorActions ( this, theme );
setAutoFormatting ( QTextEdit::AutoNone );
m_QTextDocument = document();
m_QTextDocument->setHtml ( "<p>New Document</p>" );
.......
}
void TextEditor::InsertImage ( const QString &file )
{
QUrl Uri ( QString ( "file://%1" ).arg ( file ) );
QImage image = QImageReader ( file ).read();
m_QTextDocument->addResource ( QTextDocument::ImageResource, Uri, QVariant ( file ) );
QTextCursor cursor = textCursor();
QTextImageFormat imageFormat;
imageFormat.setWidth( image.width() );
imageFormat.setHeight( image.height() );
imageFormat.setName( Uri.toString() );
cursor.insertImage(imageFormat);
setLineWrapColumnOrWidth( lineWrapColumnOrWidth() );
}
To copy to clipboard, switch view to plain text mode
This works great but QTextDocument didn't Render the Image. There is an Place holder Image but not the Real Image. The HTML Document is Valid and Wellformed HTML Document and I can view it with my Konqueror.
My Question throw my Problem, what must I do to render the Image after inserting into QTextEdit?
Bookmarks