PDA

View Full Version : QTextEdit and insertImage() Display on the Fly..



Undefined
13th July 2008, 19:43
I'm insert Images via QFileDialog into my QTextEdit Class.


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() );
}

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?

Undefined
13th July 2008, 19:48
My first Post after 2 Years and then i have send i'm found my error, sorry. :-)


m_QTextDocument->addResource ( QTextDocument::ImageResource, Uri, QVariant ( image ) );