Results 1 to 5 of 5

Thread: QTextEdit::setHtml(): how can I pass a string with an embedded image?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    23
    Thanked 15 Times in 11 Posts

    Default QTextEdit::setHtml(): how can I pass a string with an embedded image?

    Hello,
    is it possibile to pass to setHtml() a string with a self-contained image? I know I can do the following:

    Qt Code:
    1. QString html;
    2. html.append("<img src=\"c:\\temp\\sample.png\">");
    3. myTextEdit->setHtml(html);
    To copy to clipboard, switch view to plain text mode 

    and it works. However, I would like to get rid of the external image file (I am generating it at runtime).

    My first attempt was to build the html incrementally by repeteadly calling QTextEdit::insertHtml() and QTextEdit::insertImage(), but that messes things up. I guess that's because I am generating the html by recursion (visiting a tree), so the "start" and "end" tags are usually separated by many calls to "insertHtml()", and formatting gets lost in the way.

    I also tried to encode the images in the html using some "base64" encoding snippet found on the net, but it doesn't work.

    Thanks

    Qt 4.5.1, Vista Sp1, VS Express 2008

  2. The following user says thank you to mattc for this useful post:

    NicholasSmith (25th August 2009)

Similar Threads

  1. ActiveQt: How to pass image to ActiveX object?
    By AndreasSchlempp in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2009, 13:44
  2. QTableWidgetItems, String + Image
    By shooogun in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2008, 05:53
  3. Create pixmap image from string
    By Morea in forum Qt Programming
    Replies: 5
    Last Post: 17th November 2006, 17:38

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.