printer
->setPageMargins
(20,
20,
5,
20,
QPrinter::Millimeter);
mainReport.setHtml(*this->mainReportTextHtml);
mainReport.setPageSize(printer->pageRect().size());
QRect innerRect
= printer
->pageRect
();
innerRect.setTop(innerRect.top());
innerRect.setBottom(innerRect.bottom());
int pageCount = 0;
// main report
painter.save();
painter.translate(0, 30);
while (currentRect.intersects(contentRect)) {
mainReport.drawContents(&painter, currentRect);
pageCount++;
currentRect.translate(0, currentRect.height());
painter.restore();
painter.
drawText(10,
10,
QString("Header %1").
arg(pageCount
));
painter.
drawText(10, printer
->pageRect
().
bottom() - 10,
QString("Footer %1").
arg(pageCount
));
painter.save();
painter.translate(0, - currentRect.height() * pageCount + 30);
if (currentRect.intersects(contentRect))
printer->newPage();
}
//now print the second textdocument
test.setHtml(*this->proteinMeatTableHtml);
test.setPageSize(printer->pageRect().size());
printer->newPage();
painter.restore();
painter.save();
painter.translate(0, 30);
contentRect
= QRect(QPoint(0,
0), test.
size().
toSize());
int offset = 0;
while (currentRect.intersects(contentRect)) {
test.drawContents(&painter, currentRect);
pageCount++;
offset++;
currentRect.translate(0, currentRect.height());
painter.restore();
painter.
drawText(10,
10,
QString("Header %1").
arg(pageCount
));
painter.
drawText(10, printer
->pageRect
().
bottom() - 10,
QString("Footer %1").
arg(pageCount
));
painter.save();
painter.translate(0, - currentRect.height() * offset + 30);
if (currentRect.intersects(contentRect))
printer->newPage();
}
painter.restore();
painter.end();
printer->setPageMargins(20, 20, 5, 20, QPrinter::Millimeter);
QTextDocument mainReport;
mainReport.setHtml(*this->mainReportTextHtml);
mainReport.setPageSize(printer->pageRect().size());
QRect innerRect = printer->pageRect();
innerRect.setTop(innerRect.top());
innerRect.setBottom(innerRect.bottom());
QRect contentRect = QRect(QPoint(0,0), mainReport.size().toSize());
QRect currentRect = QRect(QPoint(0,0), innerRect.size());
QPainter painter(printer);
int pageCount = 0;
// main report
painter.save();
painter.translate(0, 30);
while (currentRect.intersects(contentRect)) {
mainReport.drawContents(&painter, currentRect);
pageCount++;
currentRect.translate(0, currentRect.height());
painter.restore();
painter.drawText(10, 10, QString("Header %1").arg(pageCount));
painter.drawText(10, printer->pageRect().bottom() - 10, QString("Footer %1").arg(pageCount));
painter.save();
painter.translate(0, - currentRect.height() * pageCount + 30);
if (currentRect.intersects(contentRect))
printer->newPage();
}
//now print the second textdocument
QTextDocument test;
test.setHtml(*this->proteinMeatTableHtml);
test.setPageSize(printer->pageRect().size());
printer->newPage();
painter.restore();
painter.save();
painter.translate(0, 30);
contentRect = QRect(QPoint(0,0), test.size().toSize());
currentRect = QRect(QPoint(0,0), innerRect.size());
int offset = 0;
while (currentRect.intersects(contentRect)) {
test.drawContents(&painter, currentRect);
pageCount++;
offset++;
currentRect.translate(0, currentRect.height());
painter.restore();
painter.drawText(10, 10, QString("Header %1").arg(pageCount));
painter.drawText(10, printer->pageRect().bottom() - 10, QString("Footer %1").arg(pageCount));
painter.save();
painter.translate(0, - currentRect.height() * offset + 30);
if (currentRect.intersects(contentRect))
printer->newPage();
}
painter.restore();
painter.end();
To copy to clipboard, switch view to plain text mode
Bookmarks