Skip to content

Commit

Permalink
QGLWidget: Prevent premature platform window creation
Browse files Browse the repository at this point in the history
Passing Qt::MSWindowsOwnDC along with the window flags to the QWidget
constructor results in creating a native window as part of the base
class initialization.

By deferring the window creation to later in the QGLWidget construction,
the meta object reflects the actual class.

Change-Id: I51343c767057d6841331614b93ad860fe99d65e3
Reviewed-by: Simon Hausmann <[email protected]>
Reviewed-by: Tor Arne Vestbø <[email protected]>
  • Loading branch information
torarnv committed Oct 31, 2018
1 parent 7087a68 commit b75babc
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/opengl/qgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3880,25 +3880,19 @@ void QGLContext::doneCurrent()
*/

QGLWidget::QGLWidget(QWidget *parent, const QGLWidget* shareWidget, Qt::WindowFlags f)
: QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC)
: QWidget(*(new QGLWidgetPrivate), parent, f)
{
Q_D(QGLWidget);
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
setAutoFillBackground(true); // for compatibility
d->init(new QGLContext(QGLFormat::defaultFormat(), this), shareWidget);
}

/*!
\internal
*/
QGLWidget::QGLWidget(QGLWidgetPrivate &dd, const QGLFormat &format, QWidget *parent, const QGLWidget *shareWidget, Qt::WindowFlags f)
: QWidget(dd, parent, f | Qt::MSWindowsOwnDC)
: QWidget(dd, parent, f)
{
Q_D(QGLWidget);
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
setAutoFillBackground(true); // for compatibility
d->init(new QGLContext(format, this), shareWidget);

}
Expand Down Expand Up @@ -3935,12 +3929,9 @@ QGLWidget::QGLWidget(QGLWidgetPrivate &dd, const QGLFormat &format, QWidget *par

QGLWidget::QGLWidget(const QGLFormat &format, QWidget *parent, const QGLWidget* shareWidget,
Qt::WindowFlags f)
: QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC)
: QWidget(*(new QGLWidgetPrivate), parent, f)
{
Q_D(QGLWidget);
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
setAutoFillBackground(true); // for compatibility
d->init(new QGLContext(format, this), shareWidget);
}

Expand Down Expand Up @@ -3971,12 +3962,9 @@ QGLWidget::QGLWidget(const QGLFormat &format, QWidget *parent, const QGLWidget*
*/
QGLWidget::QGLWidget(QGLContext *context, QWidget *parent, const QGLWidget *shareWidget,
Qt::WindowFlags f)
: QWidget(*(new QGLWidgetPrivate), parent, f | Qt::MSWindowsOwnDC)
: QWidget(*(new QGLWidgetPrivate), parent, f)
{
Q_D(QGLWidget);
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
setAutoFillBackground(true); // for compatibility
d->init(context, shareWidget);
}

Expand Down Expand Up @@ -5169,6 +5157,15 @@ QPaintEngine *QGLWidget::paintEngine() const

void QGLWidgetPrivate::init(QGLContext *context, const QGLWidget *shareWidget)
{
Q_Q(QGLWidget);
q->setAttribute(Qt::WA_PaintOnScreen);
q->setAttribute(Qt::WA_NoSystemBackground);
q->setAutoFillBackground(true); // for compatibility

mustHaveWindowHandle = 1;
q->setAttribute(Qt::WA_NativeWindow);
q->setWindowFlag(Qt::MSWindowsOwnDC);

initContext(context, shareWidget);
}

Expand Down

0 comments on commit b75babc

Please sign in to comment.