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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.