屏幕截图与qgraphicsview

时间:2013-12-18 05:00:47

标签: qt opengl-es

我有一个用qt5编写的浏览器应用程序用于我的嵌入式主板。我需要opengl渲染到aplication。所以代码就像

myGraphicsView->setViewport(new QGLWidget(QGLFormat(QGL::NoDepthBuffer |QGL::NoStencilBuffer |QGL::NoSampleBuffers)));

我想拍摄网页的截图。我怎么能得到它。使用QPixmap :: grabFrameBuffer和grabWindow.But只有白屏。

1 个答案:

答案 0 :(得分:0)

我在互联网上找到并尝试过,效果很好:

//Get the size of your graphicsview
QRect rect = MyGrView->viewport()->rect();

//Create a pixmap the same size as your graphicsview
//You can make this larger or smaller if you want.
QPixmap pixmap(rect.size());
QPainter painter(&pixmap);//QPainter does not support coordinates larger than +/- 32768

//Render the graphicsview onto the pixmap and save it out.
MyGrView->render(&painter, pixmap.rect(), rect);
pixmap.save("C:/1.png","PNG");

QPainter limitations