0

Given a QGraphicScene and a QGraphicView how can I write a jpg file from that?

qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));

QGraphicsScene *scene = new QGraphicsScene();
scene->setSceneRect(-300, -300, 600, 600);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);

qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));

myPlot *myplot = new myPlot;
scene->addItem(myplot);

QGraphicsView *view = new QGraphicsView();
view->setScene(scene);
view->setRenderHint(QPainter::Antialiasing);
view->setBackgroundBrush(Qt::yellow);
view->setCacheMode(QGraphicsView::CacheBackground);
view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view->setDragMode(QGraphicsView::ScrollHandDrag);
view->setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice"));
view->resize(1000, 800);
view->show();
4

1 回答 1

3
QImage img(yourScene->sceneRect().width(), yourScene->sceneRect().height(), QImage::Format_ARGB32);
QPainter painter(&img);
yourScene->render(&painter, yourScene->sceneRect());
img.save("scene.jpg");
于 2013-07-23T17:39:48.727 回答