Hi there,

I would like to achieve what is being done in the overpaint example of QGLViewer: render a 3D scene with OpenGL and paint something *on top* of that with a QPainter. I followed the instructions on that website and did this:

Qt Code:
  1. class OpenGLWidget: public QGLViewer
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. OpenGLWidget(QWidget* parent=0);
  7. ~OpenGLWidget();
  8.  
  9. protected:
  10. void paintEvent(QPaintEvent *event); // override paintEvent
  11.  
  12. };
  13.  
  14. OpenGLWidget::OpenGLWidget(QWidget *parent) : QGLViewer(parent)
  15. {
  16. setAttribute(Qt::WA_NoSystemBackground);
  17. }
  18.  
  19. void OpenGLWidget::paintEvent(QPaintEvent *event)
  20. {
  21. QGLViewer::paintEvent(event); // Do what the overridden method would do.
  22.  
  23. // Paint something with QPainter.
  24. QPainter painter;
  25. painter.setBackgroundMode(Qt::TransparentMode);
  26. painter.begin(this); // This is where it happens.
  27. painter.setPen(colorUtil.penBlueThick);
  28. painter.drawLine(0, 0, 100, 100);
  29. }
To copy to clipboard, switch view to plain text mode 

Unfortunately this does not have the desired effect. When I begin() the painter, the background is cleared and the 3D rendering disappears. Setting the background mode to transparent, and setting the widget attribute to NoSystemBackground have no effect. Can anyone help me along please?

Thanks
Cruz