PDA

View Full Version : Printing complex page with changing data



marcvanriet
21st December 2010, 00:01
Hi,

For all members of our sports club I have a nice page (see attachment) which I can print that contains their contact information, a picture, graduation data, payment data, etc...

Right now I create these pages using a desktop publishing application, and maintain a page for each member. This takes a lot of time, so I want to put the data in a database and print the pages using a Qt application.

I know how to get everything from my database, and know how to print simple pages. I am seeking advice on how to handle such a complex page. I see several options :

1) do all the painting myself on a QPainter. This gives me the most control, but requires me to program every line and rectangle on the page, which takes a lot tweeking before you get it right. Also it would take a lot of time and possibly rework if I would ever need to rearrange the elements, e.g. to make room for new data.

2) create a richt text document with placeholders for the data, fill in the data, and print this document. I doubt that a rich text document can handle different elements that are arranged anywhere on a page, and all the borders and other graphical elements.

3) create a html document and read this. I believe I still have to use a QTextDocument to read the HTML, and not all HTML features will be supported.

4) create a .ODT file and read this. Same as above ?

5) draw an SVG image with all the graphical elements of the page. Then read this image, paint it on a QPainter, and paint all the data on top of it. Then I just have to fiddle around until I get all the data elements at the right position. Or maybe I can put placeholders in the SVG image and replace them with the correct data ?

Any advice ?

Thanks in advance,
Marc

Lykurg
21st December 2010, 07:01
You have named all possibilities. The final choice is yours!

I would probably go for a combination of HTML and "hand written" QPainter. E.g. do simple tables with HTML, since you don't need all HTML/CSS features for that, so that the QTextDocument supported one are fine. Query the size of the fragment and place it by hand on the page. Fancy frames I would paint directly with QPainter. Etc.

marcvanriet
21st December 2010, 21:26
Hi Lykurg, thanks for the reply.

Query the size of the fragment and place it by hand on the page.
What do you mean by this ?

Digging further in the documentation of the RTF classes, I see I could make a document in any RTF/HTML editor with different frames and tables. I could read this file and fill in the necessary data using a QTextCursor. I could then iterate over the QTextDocument and find my different tables and frames. But then I don't see how to proceed. How could you query the size of the different elements, or paint them manually ? A QTextDocument has drawContents() function, but not QTextTable or so. And I don't see anything anywhere for querying the size.


The final choice is yours!
Yes, but I prefer to make an informed decision, if possible based on experience and advice of other people :)

Regards,
Marc

Lykurg
21st December 2010, 23:45
I meant following:

QTextDocumet doc;
doc.setHtml("<table>...</table>");
// here you don't know how big the table is, so
QSizeF s = doc.size();
with that information (QSizeF) you can position the table when you translate the painter and call QTextDocument::drawContents().

So split the page layout into bigger pieces like tables, pictures, frames etc., query their sizes and arrange them according your layout. If you could do all these in one rtf or html document, then go for it. (but since not all features of HTML are supported it could be difficult.)

marcvanriet
22nd December 2010, 01:15
OK, I see, thanks.

I thought the size() function would always be the 'paper size', not the size of the contents. I'll see if I can get it to work.

Best regards,
Marc