1

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++;
                }
            }
        }
    }
}

それが効果です(PDFファイル): 印刷の問題

リストのすべてのポイントは単一の QGraphicsItem であり、ページ内に収まらないアイテムを次のページに移動する最も簡単な方法は何なのかわかりません...おそらくエラーが発生しやすい数学を実行して達成することができますしかし、これはエレガントな方法で解決できると確信しています。

4

1 に答える 1