Skip to content

Commit

Permalink
QWindowWindow: Avoid resize events from the ctor
Browse files Browse the repository at this point in the history
When calling showFullScreen(), the setwindowStates call in the
QWindowsWindow constructor led to generating a resize event. This is
pretty bad for example when QOpenGLWindow is involved since the QWindow's
platformWindow member is not even set yet (handle() == nullptr) so
everything related to OpenGL contexts starts failing (as there is no
underlying platform window yet as far as the QWindow is concerned).

In short, generating geometry changes from the platformwindow ctor is a
bad idea. Use initialize() instead for that.

Task-number: QTBUG-67027
Change-Id: I35d11949213eb21f81b2ff2d4f2282cb36510210
Reviewed-by: Friedemann Kleint <[email protected]>
  • Loading branch information
alpqr committed Mar 13, 2018
1 parent aaace8f commit a060ee2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/gui/kernel/qopenglwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ void QOpenGLWindowPrivate::initialize()
if (context)
return;

if (!q->handle())
qWarning("Attempted to initialize QOpenGLWindow without a platform window");

context.reset(new QOpenGLContext);
context->setShareContext(shareContext);
context->setFormat(q->requestedFormat());
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/platforms/windows/qwindowswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,6 @@ QWindowsWindow::QWindowsWindow(QWindow *aWindow, const QWindowsWindowData &data)
updateDropSite(window()->isTopLevel());

registerTouchWindow();
setWindowState(aWindow->windowStates());
const qreal opacity = qt_window_private(aWindow)->opacity;
if (!qFuzzyCompare(opacity, qreal(1.0)))
setOpacity(opacity);
Expand Down Expand Up @@ -1136,9 +1135,11 @@ void QWindowsWindow::initialize()
QWindowCreationContextPtr creationContext =
QWindowsContext::instance()->setWindowCreationContext(QWindowCreationContextPtr());

QWindow *w = window();
setWindowState(w->windowStates());

// Trigger geometry change (unless it has a special state in which case setWindowState()
// will send the message) and screen change signals of QWindow.
QWindow *w = window();
if (w->type() != Qt::Desktop) {
const Qt::WindowState state = w->windowState();
if (state != Qt::WindowMaximized && state != Qt::WindowFullScreen
Expand Down

0 comments on commit a060ee2

Please sign in to comment.