PDA

View Full Version : Add HTML to QTextDocument with HTML containing QImage



Taxi
13th February 2012, 13:04
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::print()).

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.

roxton
13th February 2012, 16:29
Try to save your QImage into the temporary file, then make a link to that file at your HTML code. Then print :)

Taxi
13th February 2012, 16:37
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...

Lykurg
13th February 2012, 18:06
Look at the wiki article I wrote long long time ago. It should nevertheless still work: QTextBrowser with images and CSS

Taxi
13th February 2012, 18:09
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 :-)