Printing and total page count in header/footer



  • Hi,
    I'm trying printing in Qt and I got stuck with one thing. Is there some way how to print total page count in header/footer of every page? something like "Page 1 of 5"
    The only way I can think of is to save qpainter state in the beginning, "print" everything, count the pages, restore the state and then print it for real, with the right header/footer.
    Is there some better way?



  • Why dont u use "qprintpreview::pagecount()":http://doc.qt.nokia.com/4.7/qprintpreviewwidget.html#pageCount



  • but qprintpreview::pagecount is based on the printed content, isn't it? so firstly I have to create the content to get the pagecount, but I want the content already created with footer like "Page 1 of 5"



  • But how you know how much pages you gonna print then? And if you now it in front then you can just print it.

    Of course you can also count the lines you gonna print devided by the number of lines the selected papersource can print.



  • that is the problem - i don't know how many pages i'm gonna print.. so the only way to get the page count is to preprocess the printed content? It would be nice to have a way to get back to previous pages once I call QPainter::newPage.. I could then write the page count to all previous pages...



  • As I understand your problem you are asking if you can go back the already rendered pages and modify the footer with the number of pages after you rendered all of them. As I know it is not possible.

    So the solution is somehow foresee (with an interim datamodel or the way you mentioned in your original post) how many pages you have and write it to the footer as you render the pages.



  • ah, OK then :) I thought so, but I wanted to be sure whether there is some better way .. thanks for the replies :)



  • If you're printing a QTextDocument see http://developer.qt.nokia.com/faq/answer/is_it_possible_to_set_a_header_and_footer_when_printing_a_qtextdocument

    Otherwise, I'd be happy to see a QPrinter API that gives you a list of QPictures (=> what was printed) and lets the user modify them (by overpainting things etc.), then sends them to the actual printer.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.