QT 中 QGLWidget 不能够嵌入到 QGraphicsView 中及解决方案

时间:2022-09-10 18:36:17

症状:

QPainter::begin: A paint device can only be painted by one painter at a time.

参考资料:

http://www.qtcentre.org/archive/index.php/t-20669.html

https://bugreports.qt.nokia.com//browse/QTBUG-18813

http://developer.qt.nokia.com/forums/viewthread/5412/

http://doc.trolltech.com/qq/qq26-openglcanvas.html

原因:

QGraphicsScene::addWidget() creates a QGraphicsProxyWidget which does not support widgets which draw directly onto the screen, like a QGLWidget

解决方案:

将QGLWidget设置为QGraphicsView的viewport,然后在QGraphicsView::drawBackground() and QGraphicsView::drawForeground() 中实现渲染