How can I print the content of a QGraphicsView
in Qt?
Thanks a lot.
QGraphicsView visualizes the contents of a QGraphicsScene in a scrollable viewport. To create a scene with geometrical items, see QGraphicsScene's documentation. QGraphicsView is part of the Graphics View Framework.
Graphics View provides a surface for managing and interacting with a large number of custom-made 2D graphical items, and a view widget for visualizing the items, with support for zooming and rotation.
QGraphicsScene is part of the Graphics View Framework. QGraphicsScene also provides functionality that lets you efficiently determine both the location of items, and for determining what items are visible within an arbitrary area on the scene.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With