printer
->setPageMargins
(15,
15,
15,
15,
QPrinter::Millimeter);
const QRect pageRect
= printer
->pageRect
();
// Give the document the correct left-to-right width for word wrapping etc
doc.setPageSize(pageRect.size());
// The total extent of the content (there are no page margin in this)
// This is the part of the content we will drop on a page. It's a sliding window on the content.
QRect currentRect
(0,
0, pageRect.
width(), pageRect.
height());
while (currentRect.intersects(contentRect)) {
painter.save();
painter.translate(0, -currentRect.y());
doc.drawContents(&painter, currentRect); // draws part of the document
painter.restore();
// Translate the current rectangle to the area to be printed for the next page
currentRect.translate(0, currentRect.height());
//Inserting a new page if there is still area left to be printed
if (currentRect.intersects(contentRect))
printer->newPage();
}
printer->setPageMargins(15, 15, 15, 15, QPrinter::Millimeter);
const QRect pageRect = printer->pageRect();
// Give the document the correct left-to-right width for word wrapping etc
doc.setPageSize(pageRect.size());
// The total extent of the content (there are no page margin in this)
QRect contentRect = QRect(QPoint(0, 0), doc.size().toSize());
// This is the part of the content we will drop on a page. It's a sliding window on the content.
QRect currentRect(0, 0, pageRect.width(), pageRect.height());
QPainter painter(printer);
while (currentRect.intersects(contentRect)) {
painter.save();
painter.translate(0, -currentRect.y());
doc.drawContents(&painter, currentRect); // draws part of the document
painter.restore();
// Translate the current rectangle to the area to be printed for the next page
currentRect.translate(0, currentRect.height());
//Inserting a new page if there is still area left to be printed
if (currentRect.intersects(contentRect))
printer->newPage();
}
To copy to clipboard, switch view to plain text mode
Bookmarks