Using a QGLWidget as the viewport for QGraphicsView results in black screen
<p>I have a QGraphicsView displaying a QGraphicsScene which I would like to use a QGLWidget as the viewport for. The Qt <a href="http://doc.qt.io/qt-4.8/qgraphicsview.html#details" rel="nofollow noreferrer">documentation</a> leads me to believe that it is a simple as giving my QGraphicsScene a QGLWidget as a viewport, however I get a black screen when I try.</p>

<pre><code>#include &lt;QGraphicsView&gt;
#include &lt;QGraphicsScene&gt;
#include &lt;QGraphicsPixmapItem&gt;
#include &lt;QGLWidget&gt;

class View : public QGraphicsView
{
  Q_OBJECT
public:
  explicit View(QWidget *parent = 0) :
    QGraphicsView(parent)
  {
    QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(QPixmap(":/images/chart.png"));

    QGraphicsScene *scene = new QGraphicsScene();
    scene-&gt;addItem(pixmapItem);
    setScene(scene);

    setViewport(new QGLWidget());
  }
};
</code></pre>

<p>If I comment the last to lines pertaining to the QGLWidget then my pixmap displays fine, however with them in I only see a black screen. I have also noticed that the CPU usage is significantly higher when the QGLWidget is in. I have successfully used QGLWidgets in the past (never with a QGraphicsView though) so I think that OpenGL itself is working correctly. I have tried changed the gl clear color to try to see a change but it remains black. I have also tried it using both Qt 4 and Qt 5.</p>