I have a QGraphicsView displaying a QGraphicsScene which I would like to use a QGLWidget as the viewport for. The Qt documentation 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.
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QGLWidget>
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->addItem(pixmapItem);
setScene(scene);
setViewport(new QGLWidget());
}
};
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.