I want to print everything what's on QGraphicsScene:
void MainWindow::on_print_clicked()
{
if (template_ptr != Q_NULLPTR) {
QPrinter printer(QPrinter::HighResolution);
if (QPrintDialog(&printer, this).exec() == QDialog::Accepted) {
if (QPageSetupDialog(&printer, this).exec() == QDialog::Accepted) {
QPainter painter(&printer);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::TextAntialiasing);
qreal x, _y, h, w, fake;
ui->graphicsView->sceneRect().getRect(&x, &_y, &w, &fake);
h = template_ptr->page_height*2.0;
qint32 page = 0;
while (true) {
qreal y = _y + h*page;
QRectF leftRect(x, y, w, template_ptr->page_height*2.0*template_ptr->max_pages - h*page);
if (ui->graphicsView->scene()->items(leftRect).length() <= 0) {
break;
}
QRectF sourceRect(x, y, w, h);
ui->graphicsView->scene()->render(&painter, printer.pageRect(), sourceRect);
printer.newPage();
page++;
}
}
}
}
}
Every point on the lists is a single QGraphicsItem and I don't know what's the easiest way to move the items that doesn't fit within a page, to the next page... I probably could do some error-prone mathematics to achieve that but I'm pretty sure this can be resolved in some elegant way.