Results 1 to 5 of 5

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

Hybrid 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 Re: QTextEdit::setHtml(): how can I pass a string with an embedded image?

    Thank you Lykurg,
    it works pretty well! Here is the working code for future reference:

    Qt Code:
    1. QString html;
    2.  
    3. QImage img("c:\\temp\\sample.png"); // todo: generate image in memory
    4. myTextEdit->document()->addResource(QTextDocument::ImageResource, QUrl("sample.png" ), img);
    5.  
    6. html.append("<p><img src=\":sample.png\"></p>");
    7.  
    8. myTextEdit->setHtml(html);
    To copy to clipboard, switch view to plain text mode 

  2. The following 2 users say thank you to mattc for this useful post:

    ehxor (28th October 2012), sivambigai (15th November 2010)

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.