How can I print the content of a QGraphicsView
in Qt?
Thanks a lot.
How can I print the content of a QGraphicsView
in Qt?
Thanks a lot.
Take a look at the official Qt documentation: http://doc.qt.io/archives/4.6/graphicsview.html#printing
For further reference:
"Graphics View provides single-line printing through its rendering functions, QGraphicsScene::render()
and QGraphicsView::render()
. The functions provide the same API: You can have the scene or the view render all or parts of their contents into any paint device by passing a QPainter
to either of the rendering functions. This example shows how to print the whole scene into a full page, using QPrinter
."
Example:
QGraphicsScene scene;
scene.addRect(QRectF(0, 0, 100, 200), QPen(Qt::black), QBrush(Qt::green));
QPrinter printer;
if (QPrintDialog(&printer).exec() == QDialog::Accepted) {
QPainter painter(&printer);
painter.setRenderHint(QPainter::Antialiasing);
scene.render(&painter);
}
© 2022 - 2024 — McMap. All rights reserved.