How to print content of a QGraphicsView
Asked Answered
S

1

6

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

Thanks a lot.

Savadove answered 27/9, 2010 at 11:3 Comment(0)
A
7

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);
}
Atlantes answered 27/9, 2010 at 12:6 Comment(1)
Thanks a lot I try it and it run. But I have a problem. My scene rect about (0,0,2700,800) and its unreadable. Do you think any solution about it?Savadove

© 2022 - 2024 — McMap. All rights reserved.