Results 1 to 2 of 2

Thread: QTextEdit and insertImage() Display on the Fly..

  1. #1
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QTextEdit and insertImage() Display on the Fly..

    I'm insert Images via QFileDialog into my QTextEdit Class.
    Qt Code:
    1. TextEditor::TextEditor ( QWidget *parent, HJcmsSettings *cfg, HJcmsIconTheme *theme )
    2. : QTextEdit ( parent )
    3. , m_HJcmsSettings ( cfg )
    4. , m_HJcmsIconTheme ( theme )
    5. {
    6. m_HtmlEditorActions = new HtmlEditorActions ( this, theme );
    7.  
    8. setAutoFormatting ( QTextEdit::AutoNone );
    9. m_QTextDocument = document();
    10. m_QTextDocument->setHtml ( "<p>New Document</p>" );
    11. .......
    12. }
    13.  
    14. void TextEditor::InsertImage ( const QString &file )
    15. {
    16. QUrl Uri ( QString ( "file://%1" ).arg ( file ) );
    17. QImage image = QImageReader ( file ).read();
    18.  
    19. m_QTextDocument->addResource ( QTextDocument::ImageResource, Uri, QVariant ( file ) );
    20.  
    21. QTextCursor cursor = textCursor();
    22. QTextImageFormat imageFormat;
    23. imageFormat.setWidth( image.width() );
    24. imageFormat.setHeight( image.height() );
    25. imageFormat.setName( Uri.toString() );
    26. cursor.insertImage(imageFormat);
    27. setLineWrapColumnOrWidth( lineWrapColumnOrWidth() );
    28. }
    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?

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTextEdit and insertImage() Display on the Fly..

    My first Post after 2 Years and then i have send i'm found my error, sorry. :-)
    Qt Code:
    1. m_QTextDocument->addResource ( QTextDocument::ImageResource, Uri, QVariant ( image ) );
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Undefined for this useful post:

    jacek (14th July 2008)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.