Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print content of a QGraphicsView

How can I print the content of a QGraphicsView in Qt?

Thanks a lot.

like image 245
ayla Avatar asked Sep 27 '10 11:09

ayla


People also ask

What is QGraphicsView?

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.

What is the Graphics View in Qt Designer Python?

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.

What is QGraphicsScene?

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.


1 Answers

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);
}
like image 140
Greg S Avatar answered Nov 02 '22 17:11

Greg S