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:
class OpenGLWidget: public QGLViewer
{
Q_OBJECT
public:
~OpenGLWidget();
protected:
void paintEvent
(QPaintEvent *event
);
// override paintEvent
};
OpenGLWidget
::OpenGLWidget(QWidget *parent
) : QGLViewer
(parent
){
setAttribute(Qt::WA_NoSystemBackground);
}
{
QGLViewer::paintEvent(event); // Do what the overridden method would do.
// Paint something with QPainter.
painter.setBackgroundMode(Qt::TransparentMode);
painter.begin(this); // This is where it happens.
painter.setPen(colorUtil.penBlueThick);
painter.drawLine(0, 0, 100, 100);
}
class OpenGLWidget: public QGLViewer
{
Q_OBJECT
public:
OpenGLWidget(QWidget* parent=0);
~OpenGLWidget();
protected:
void paintEvent(QPaintEvent *event); // override paintEvent
};
OpenGLWidget::OpenGLWidget(QWidget *parent) : QGLViewer(parent)
{
setAttribute(Qt::WA_NoSystemBackground);
}
void OpenGLWidget::paintEvent(QPaintEvent *event)
{
QGLViewer::paintEvent(event); // Do what the overridden method would do.
// Paint something with QPainter.
QPainter painter;
painter.setBackgroundMode(Qt::TransparentMode);
painter.begin(this); // This is where it happens.
painter.setPen(colorUtil.penBlueThick);
painter.drawLine(0, 0, 100, 100);
}
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
Bookmarks