Results 1 to 14 of 14

Thread: Add images or screenshots to a html doc

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2015
    Posts
    22
    Thanks
    18
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Add images or screenshots to a html doc

    I'm currently trying to use pixmap, spent a couple of hours on it already.

  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: Add images or screenshots to a html doc

    You can use QPixmap, but you have to use QPixmap::save() to save it to a buffer (i.e. a QIODevice mapped to an in-memory buffer), then pass that buffer to a base64 encoder that will return the string. In order for the HTML to make sense of it, it has to be an exact copy of what a PNG file on disk looks like, when converted to base64. Simply writing out the bytes of a QPixmap won't work, it has to be converted to an image type that is recognized by the <img/> element.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Add images or screenshots to a html doc

    QWidget::grab() to get an image of the widget
    Save the image to a temporary file (QTemporaryFile maybe)
    QUrl::fromLocalFile() to get a URL you can use in the src attribute of the img element.

    I do not know of a way to suppress the page number when using the print() convenience function.

    You will likely get a better quality result by directly rendering to a QPrinter or similar, but this is more work.

  4. The following user says thank you to ChrisW67 for this useful post:

    guiismiti (8th February 2015)

  5. #4
    Join Date
    Jan 2015
    Posts
    22
    Thanks
    18
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Add images or screenshots to a html doc

    I'm saving the pixmap inside C:/Temp, but I'm gonna use QTemporaryFile instead.

    And now I've got a another problem. It's with my HTML code.
    It is not recognizing some tags for the images I'm using.

    Both "alt" (first image) and "width" and "height" (second image) are not working.
    Qt Code:
    1. "<html>"
    2. "<body>"
    3. "<font size='4' face='Arial'>"
    4. "<h1 align='center'>Title 1</h1>"
    5. "<p align='center'><img src=':/images/applogo.png' alt='applogo'></p>" //this is the app logo
    6. "<h2 align='center'>Title 2</h2>"
    7. "<p align='center'>Chart title"
    8. "<br><img src='C:/Temp/temp.png' height='241' width='621'></p>" //this is the chart
    9. "</font>"
    10. "</body>"
    11. "</html>"
    To copy to clipboard, switch view to plain text mode 

    I really need the width/height tags to work, since the chart is being stretched to the page size, and the resolution isn't good, especially for papers.
    Any ideas?

  6. #5
    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: Add images or screenshots to a html doc

    The <img> tags aren't valid HTML - the closing ">" is missing the "/" ("/>") Likewise with the "<br>" tag. (Although I'm not an HTML expert - I know HTML syntax is sloppy compared to the requirements of XML and SGML).

  7. #6
    Join Date
    Jan 2015
    Posts
    22
    Thanks
    18
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Add images or screenshots to a html doc

    Quote Originally Posted by d_stranz View Post
    The <img> tags aren't valid HTML - the closing ">" is missing the "/" ("/>") Likewise with the "<br>" tag. (Although I'm not an HTML expert - I know HTML syntax is sloppy compared to the requirements of XML and SGML).
    I have just noticed that and tried to correct it, still won't work.
    Also tried to remove the ' from the width/height values, nothing.

  8. #7
    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: Add images or screenshots to a html doc

    Maybe it is because the "img" tags are inside the "font" tags? But I'm guessing, too - I don't do HTML, so I don't know the proper syntax or semantics. Or maybe your browser simply doesn't understand these attributes?

Similar Threads

  1. Why the images from the HTML file is not loaded??
    By rleojoseph in forum Qt Programming
    Replies: 8
    Last Post: 2nd March 2011, 11:29
  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. GIF or MNG images for use in html for QTextBrowser
    By manojmka in forum Qt Programming
    Replies: 3
    Last Post: 2nd January 2008, 16:30
  4. Loading images in html in a QTextBrowser
    By BasicPoke in forum Newbie
    Replies: 1
    Last Post: 6th June 2007, 21:51
  5. getting images out of html
    By hijinks in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2006, 23:17

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.