Results 1 to 5 of 5

Thread: Printing complex page with changing data

  1. #1
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Printing complex page with changing data

    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
    Attached Images Attached Images

  2. #2
    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: Printing complex page with changing data

    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.

  3. #3
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Printing complex page with changing data

    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

  4. #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: Printing complex page with changing data

    I meant following:
    Qt Code:
    1. QTextDocumet doc;
    2. doc.setHtml("<table>...</table>");
    3. // here you don't know how big the table is, so
    4. QSizeF s = doc.size();
    To copy to clipboard, switch view to plain text mode 
    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.)

  5. #5
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Printing complex page with changing data

    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

Similar Threads

  1. Replies: 0
    Last Post: 11th November 2010, 08:58
  2. Replies: 2
    Last Post: 28th September 2010, 10:34
  3. QWebKit, Printing and Page Numbers
    By colin207 in forum Qt Programming
    Replies: 0
    Last Post: 23rd June 2010, 18:06
  4. Once for all: fit page when printing
    By Raccoon29 in forum Newbie
    Replies: 0
    Last Post: 29th September 2008, 10:48
  5. Printing a pixmap full page: strange behavior on Windows
    By Pieter from Belgium in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2008, 12:29

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.