Results 1 to 5 of 5

Thread: Add HTML to QTextDocument with HTML containing QImage

  1. #1
    Join Date
    Jul 2011
    Location
    Belgium
    Posts
    24
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Question Add HTML to QTextDocument with HTML containing QImage

    Hi guys,

    I'm working on a print module for my application but I'm kinda stuck here.
    Short sketch:

    I want to print my Qwt plot. BUT I need "header data" on my page to be printed. I want this data to be nicely added on top of the page into a table containing multiple collumns and rows. This table containing specific data will be generated into a QStringList containing html code for the table and data. This HTML code will be added to a QTextDocument that will be printed (QTextDocument:rint()).

    Now the next step would be to add a QImage rendered from my QwtPlot (I'm using version 5.2.1 so the print function from v6 can not be used). The rendering of the image of the plot is simple. This image can also be printed apart from my QTextDocument, but now comes my problem.

    I want to add beneath my header table data my plot. So at the top of the page, there will be a table, and below that table will be my plot. So summarized: I have a QTextDocument containing HTML code for the table and a QImage containing my plot. Now what I want to do is add my QImage to my HTML code. Like this, my QTextDocument will handle all the page breaking et cetera.

    So how can I add my QImage to my excisting html code?

    For instance: I can not do this:

    QImage myImage = blablabla;
    QString html = "<table width=\"100\" border=1 cellspacing=0>\n"
    "<tr><td><b>" + title + "</b><tr><td>" + image +
    "\n</table<\n<br>\n"

    QTextDocument txtDoc;
    txtDoc.setHtml(html);
    txtDoc.print(printer);

    Trying to do for instance + image will not work. Is there any way I can do "<img src=" + image " /> or add an image to the html code ? Or adding not only the html code but also the image to the QTextDocument and how will I then be able to control the layout?

    My last option would be creating a hidden folder where I could save my QImage as a .jpg for example and then I could use the html code <img src="image.jp" /> but I'm not verry fond of using this option.

  2. #2
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Add HTML to QTextDocument with HTML containing QImage

    Try to save your QImage into the temporary file, then make a link to that file at your HTML code. Then print

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

    Taxi (13th February 2012)

  4. #3
    Join Date
    Jul 2011
    Location
    Belgium
    Posts
    24
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Add HTML to QTextDocument with HTML containing QImage

    That is the last option I want to use. But I see no other way at the moment. Still thanks!

    Problem here is that if you create a QImage from a plot, and save it to a temp file, the quality sucks. If I can use the QImage itself without saving it to the harddrive, the quality will be better.
    And yes, you can change the quality of the QImage temp file to a bigger size, et cetera, BUT I'm not working here with always the same QPrinter page size. This will depent on the costumer to which type of page size he wants to print...
    Last edited by Taxi; 13th February 2012 at 16:53.

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Add HTML to QTextDocument with HTML containing QImage

    Look at the wiki article I wrote long long time ago. It should nevertheless still work: [wiki]QTextBrowser with images and CSS[/wiki]

  6. The following user says thank you to Lykurg for this useful post:

    Taxi (13th February 2012)

  7. #5
    Join Date
    Jul 2011
    Location
    Belgium
    Posts
    24
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Add HTML to QTextDocument with HTML containing QImage

    Thank but I'm at that point at the moment! Still, with the article you need to create an image file and reload it. Trying it not with a SVG rendered plot. Better quality :-)

Similar Threads

  1. Html used in QTextEdit and QTextDocument
    By nifei in forum Qt Programming
    Replies: 5
    Last Post: 15th August 2012, 20:38
  2. QTextDocument and HTML tags
    By naga in forum Qt Programming
    Replies: 2
    Last Post: 13th December 2011, 11:22
  3. QTextDocument QPainter html
    By aekilic in forum Qt Programming
    Replies: 6
    Last Post: 25th June 2009, 19:35
  4. QTextDocument Html URL
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2008, 17:00
  5. QTextDocument Html
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2007, 12:50

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.