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. Adding a Footer to a QTextDocument?
Forum Updated to NodeBB v4.3 + New Features

Adding a Footer to a QTextDocument?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 4.9k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    LiamMaru
    wrote on last edited by
    #1

    I cant seem to find a reasonable way to do this. Any ideas? I just want to add a page number, date and copyright. I've tried "this":http://developer.qt.nokia.com/faq/answer/is_it_possible_to_set_a_header_and_footer_when_printing_a_qtextdocument, but no luck. I tried trimming it down a bit and came out with this:

    @QPainter painter(printer);
    painter.drawText(10, printer->pageRect().bottom() - 10, QString("FOOTER"));@

    Still no luck, neither piece of code actually does anything to the document.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      luca
      wrote on last edited by
      #2

      Some time ago I used this in one application:
      @
      void MyPrint::scriviFooter(QPainter *painter, QPrinter *printer, int page_number, QRect content_rect)
      {
      //LINE and ROW NUMBER:
      painter->drawLine(content_rect.left(), printer->pageRect().bottom()-FOOTER_H, content_rect.right()-70, printer->pageRect().bottom()-FOOTER_H );
      painter->drawText(content_rect.right()-60, printer->pageRect().bottom() - FOOTER_H+2, QString("Page %1").arg(page_number));

      //FOOTER TEXT:
      for(int i=0; i<footerTextList.size(); i++)
      {
          painter->drawText(content_rect.left(), printer->pageRect().bottom() - (FOOTER_H * 0.8) + 12*(i+1), footerTextList[i]);
      }
      

      }
      @

      Now I can't test it but it worked fine for me.

      FOOTER_H is the heigth of the footer you want.
      footerTextList is a QStringList containing the text of the footer.

      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