Cruz
10th May 2019, 11:31
Hi there,
I would like to achieve what is being done in the overpaint example (http://libqglviewer.com/examples/overpainting.html) 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(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);
}
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
I would like to achieve what is being done in the overpaint example (http://libqglviewer.com/examples/overpainting.html) 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(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);
}
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