Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Adding a Footer to a QTextDocument?

    General and Desktop
    2
    2
    4520
    Loading More Posts
    • 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
      LiamMaru last edited by

      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 Reply Quote 0
      • L
        luca last edited by

        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 Reply Quote 0
        • First post
          Last post