Results 1 to 4 of 4

Thread: How to show remote images in QTextEdit from html-string?

  1. #1
    Join Date
    Jun 2012
    Posts
    2
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to show remote images in QTextEdit from html-string?

    Hello guys! Need some help!
    How to show remote images in QTextEdit from html-string?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to show remote images in QTextEdit from html-string?

    QTextEdit supports the HTML 4.0 <a href=... /> element, so presumably you could put the URL of your image in that. See this link.

  3. #3
    Join Date
    Jun 2012
    Posts
    2
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to show remote images in QTextEdit from html-string?

    But it also supports "img Image Supports the src, source (for Qt 3 compatibility), width, and height attributes." You think changing to hrf will help?


    Added after 15 minutes:


    I'm trying to do it with QTextEdit::loadResource, but something goes wrong
    Qt Code:
    1. mTextEdit->setHtml(text);
    2. page = new QWebPage();
    3. QWebFrame* frame;
    4. frame = page->mainFrame();
    5. frame->setHtml(text);
    6.  
    7. foreach (QWebElement element, frame->findAllElements("img")) {
    8. QStringList attributesList = element.attributeNames();
    9. foreach (QString AttributeName, attributesList) {
    10. if(AttributeName == "src"){
    11. QUrl url;
    12. url = element.attribute(AttributeName);
    13. mTextEdit->loadResource(QTextDocument::ImageResource, url);
    14. qDebug() <<AttributeName <<":" << element.attribute(AttributeName);
    15. }
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    I can find every image link, but after loadResource nothing happen(
    Last edited by okta; 29th June 2012 at 07:00.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to show remote images in QTextEdit from html-string?

    I think loadResource() is intended for loading things from the resources compiled into the code from the resource (qrc) file, not for loading remote files from the disk or the internet.

    The "src" attribute is supported in HTML 4, you should check the WC3 HTML 4.01 specification. Click on the link to "attributes" at the top of the page to see the table of allowed attributes and the format of their values.

    It is possible that QTextEdit simply doesn't support loading remote images. I don't know, I have not tried this.

Similar Threads

  1. QWebView local web page with remote images
    By woodtluk in forum Qt Programming
    Replies: 0
    Last Post: 21st October 2010, 12:04
  2. How to use html to show overlapped images in QToolTip
    By LorenLiu in forum Qt Programming
    Replies: 0
    Last Post: 19th April 2010, 08:52
  3. QTextEdit HTML Processing of Base64 Images
    By millsks in forum Qt Programming
    Replies: 0
    Last Post: 24th November 2009, 15:02
  4. Pass remote (web) images to QImage
    By NicholasSmith in forum Qt Programming
    Replies: 2
    Last Post: 25th August 2009, 22:00
  5. Can QTextBrowser display remote images?
    By golnaz in forum Newbie
    Replies: 1
    Last Post: 21st January 2009, 13:45

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.