Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Printing and total page count in header/footer
QtWS25 Last Chance

Printing and total page count in header/footer

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 7.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    macav
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    1
    • V Offline
      V Offline
      vinb
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        macav
        wrote on last edited by
        #3

        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"

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vinb
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            macav
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • V Offline
              V Offline
              vcsala
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                macav
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dangelog
                  wrote on last edited by
                  #8

                  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.

                  Software Engineer
                  KDAB (UK) Ltd., a KDAB Group company

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved