From b75babc6ae3f0fd48d6f09f1feab7b517d078cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 22 Oct 2018 19:00:31 +0200 Subject: QGLWidget: Prevent premature platform window creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Tor Arne Vestbø --- src/opengl/qgl.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index e136ddcff2..666cc19bbe 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -3880,12 +3880,9 @@ 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); } @@ -3893,12 +3890,9 @@ QGLWidget::QGLWidget(QWidget *parent, const QGLWidget* shareWidget, Qt::WindowFl \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); } @@ -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); } @@ -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); } @@ -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); } -- cgit v1.2.3