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
-
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.
-
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.