How to print the contents of a QGraphicsView

How to print the contents of QGraphicsView in Qt?

Thank you very much.

+4
source share
1 answer

Take a look at the official Qt documentation: http://doc.qt.io/archives/4.6/graphicsview.html#printing

Additional Information:

"The graphical view provides single-line printing through its QGraphicsScene::render() and QGraphicsView::render() rendering functions. The functions provide the same API: you can have a scene or view, displaying all or parts of their contents in any drawing device, passing QPainter any of the rendering functions. This example shows how to print the entire scene to 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); } 
+5
source

All Articles