Search code examples
qtqt4qgraphicsviewqglwidget

Transparent QGLWidget on top of QGraphicsView


I'm using QGraphicsView to show a 2D image and also have a separate QGLWidget window to display some 3D object. I'm dynamically changing the image displayed in `QGraphicsView' based on the rotation of the 3D object.

I would like to render a semi-transparent 3D object on top of the 2D image, something like Maya 2009 used to do (notice the cube in the upper right corner of the viewport): Maya 2009 screenshot
(source: boulevard-creation.com)

Is it possible to do this with my current widgets? If not, how could it be done?

One option I can think of would be to render everything in QGLWidget and display the 2D image as a texture on a background plane, but that seems slightly painful.


Solution

  • I have found a way, but it is quite slow: you can simply add another QGraphicsItem to the QGraphicsScene like this

    scene->addPixmap(glWidget->renderPixmap());

    Transparency can than be set with QGraphicsItem::setOpacity().

    There should be a faster way using QPixelBuffer, but I didn't manage to render to it properly yet.