I have a custom QGraphicsScene where I reimplement the drawbackground function and draw using opengl. I am rendering everything as expected in drawbackground. However when I add a QGraphicsItem to the scene I seem to be having difficulty getting the items to render appropriately. I am able to render a QGraphicsSimpleTextItem fine, however not so much with a QGraphicsPixmapItem. If I try to just add the QGraphicsPixmapItem nothing appears on the screen, however if I add both the QGraphicsSimpleTextItem and QGraphicsPixmapItem both render fine. I have no idea why this is happening, so I am hoping by taking a look at my main function anyone might be able to steer me straight. This is just a small program designed to teach myself how to properly add items to a QGraphicsScene.

Qt Code:
  1. #include "glgraphicsscene.h"
  2.  
  3. #include <QApplication>
  4. #include <QGraphicsView>
  5. #include <QGraphicsSimpleTextItem>
  6. #include <QGraphicsPixmapItem>
  7. #include <QPixmap>
  8. #include <QDebug>
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12. QApplication app(argc, argv);
  13.  
  14. GLGraphicsScene* glScene = new GLGraphicsScene;
  15.  
  16. QGraphicsSimpleTextItem textItem("Hello QGraphicsItem!");
  17. textItem.setBrush(Qt::black);
  18.  
  19. QPixmap pixmap;
  20.  
  21. qDebug() << pixmap.load("../Bounce/graphicsview-pixmapitem.png");
  22. qDebug() << pixmap.isNull();
  23. qDebug() << pixmap.width();
  24. qDebug() << pixmap.height();
  25. qDebug() << pixmap.hasAlpha();
  26.  
  27. QGraphicsPixmapItem* gpixmap = new QGraphicsPixmapItem(pixmap);
  28. gpixmap->setVisible(true);
  29.  
  30. // this works fine all the time
  31. glScene->addItem(&textItem);
  32.  
  33. // this won't render unless line above is done first
  34. glScene->addItem(gpixmap);
  35.  
  36. // just to find out if items are being added for my benefit
  37. for(int i = 0; i < glScene->items().size(); i++)
  38. {
  39. qDebug() << glScene->items().at(i);
  40. }
  41.  
  42. view.setViewport(new QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::Rgba)));
  43. view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
  44. view.setScene(glScene);
  45. view.show();
  46.  
  47. app.exec();
  48. }
To copy to clipboard, switch view to plain text mode 

Any ideas, I haven't found anything on the internet to tell me why this won't work. Any help is greatly appreciated!