鉴于QGraphicSscene和QGraphicsView如何从中编写jpg文件?
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();
答案 0 :(得分:3)
QImage img(yourScene->sceneRect().width(), yourScene->sceneRect().height(), QImage::Format_ARGB32);
QPainter painter(&img);
yourScene->render(&painter, yourScene->sceneRect());
img.save("scene.jpg");