简体   繁体   English

使用 qgraphicsview 的屏幕截图

[英]Screenshot with qgraphicsview

I have a browser application written in qt5 for my embedded board.我有一个用 qt5 为我的嵌入式板编写的浏览器应用程序。 I need opengl rendering to the aplication .So the code is like我需要 opengl 渲染到应用程序。所以代码就像

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

I would like to take the screenshot of the webpage rendered.How can I get it.Worked with QPixmap::grabFrameBuffer and grabWindow.But got only a white screen.我想截取渲染后的网页的屏幕截图。我怎样才能得到它。与QPixmap::grabFrameBuffer 和grabWindow 一起工作。但只有一个白屏。

I found in internet and tried, it's worked:我在互联网上找到并尝试过,它奏效了:

//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 QPainter 限制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM