Important: Please read the Qt Code of Conduct -

Adding a Footer to a QTextDocument?

  • 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":, 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.

  • 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));

    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.

Log in to reply