QGraphicsView render() execute failed when set QOpenglWidget as viewport
-
I want to use QOpenglwidget combie with QGraphicsView FrameWork.So I set the QOpenglWidget as the QgraphicsView's viewport.The function of QOpenglWidget is draw background texture.
Then I add a QGraphicsTextItem to QGraphicsScene. But When I use QGraphicsView's render() function to print the screen contents into a QImage.I found that only QGrahicsTextItem is saved into QImage, the texture is not saved.
But when I directly draw texture use QPainter in QGraphicsView's drawbackground() instead of use QOpenglwidget, both the QGraphicsTextItem and background texture are save into qimage.
Why?
Below is the render related source code.m_pMyOpenglWidget = new MyOpenGLWidget(this); setViewport(m_pMyOpenglWidget); setViewportUpdateMode(QGraphicsView::FullViewportUpdate);QImage image(1920, 960, QImage::Format_ARGB32_Premultiplied); QPainter painter(&image); ui.graphicsView->render(&painter, QRectF(0, 0, showWidth, showHeight), QRect(renderLeft, renderTop, showWidth, showHeight)); painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); image.save("D://test.png");void MyGraphicsView::drawBackground(QPainter *painter, const QRectF &rect) { //Method 1:direct draw use Painter. //painter->drawImage(QPoint(0, 0), QImage("D:\\backup\\picture\\Panorama2D_1920_960.jpg")); //method2:OpenglWidget Method m_pMyOpenglWidget->drawPicturepaintGL(); }Below is Render()'s result

below is real window contents

-
I want to use QOpenglwidget combie with QGraphicsView FrameWork.So I set the QOpenglWidget as the QgraphicsView's viewport.The function of QOpenglWidget is draw background texture.
Then I add a QGraphicsTextItem to QGraphicsScene. But When I use QGraphicsView's render() function to print the screen contents into a QImage.I found that only QGrahicsTextItem is saved into QImage, the texture is not saved.
But when I directly draw texture use QPainter in QGraphicsView's drawbackground() instead of use QOpenglwidget, both the QGraphicsTextItem and background texture are save into qimage.
Why?
Below is the render related source code.m_pMyOpenglWidget = new MyOpenGLWidget(this); setViewport(m_pMyOpenglWidget); setViewportUpdateMode(QGraphicsView::FullViewportUpdate);QImage image(1920, 960, QImage::Format_ARGB32_Premultiplied); QPainter painter(&image); ui.graphicsView->render(&painter, QRectF(0, 0, showWidth, showHeight), QRect(renderLeft, renderTop, showWidth, showHeight)); painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); image.save("D://test.png");void MyGraphicsView::drawBackground(QPainter *painter, const QRectF &rect) { //Method 1:direct draw use Painter. //painter->drawImage(QPoint(0, 0), QImage("D:\\backup\\picture\\Panorama2D_1920_960.jpg")); //method2:OpenglWidget Method m_pMyOpenglWidget->drawPicturepaintGL(); }Below is Render()'s result

below is real window contents

@luzhigang some code showing what you did would help people figure out what is wrong.
preferably minimal app so people can try to reproduce it...