From 09e7a994d14a0582912551ca1342e3b695cf3a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 10 Feb 2017 15:57:11 +0100 Subject: [PATCH] Don't create platform window for QWindows when calling setVisible(false) We can defer the creation until the window is shown. Change-Id: I3d5b45ae59ee0925996cf12cd46dd574c8c6ef95 Reviewed-by: Friedemann Kleint --- src/gui/kernel/qwindow.cpp | 7 +++++-- tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 47277abea3..6092b08ea1 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -532,7 +532,9 @@ void QWindow::setVisible(bool visible) // can defer creation until the parent is created or we're re-parented. if (parent() && !parent()->handle()) return; - else + + // We only need to create the window if it's being shown + if (visible) create(); } @@ -574,7 +576,8 @@ void QWindow::setVisible(bool visible) d->applyCursor(); #endif - d->platformWindow->setVisible(visible); + if (d->platformWindow) + d->platformWindow->setVisible(visible); if (!visible) { QHideEvent hideEvent; diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 4fc18be3d2..36ec28de8d 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -56,6 +56,7 @@ private slots: void create(); void setParent(); void setVisible(); + void setVisibleFalseDoesNotCreateWindow(); void eventOrderOnShow(); void resizeEventAfterResize(); void exposeEventOnShrink_QTBUG54040(); @@ -234,6 +235,16 @@ void tst_QWindow::setVisible() QVERIFY(QTest::qWaitForWindowExposed(&i)); } +void tst_QWindow::setVisibleFalseDoesNotCreateWindow() +{ + QWindow w; + QVERIFY(!w.handle()); + w.setVisible(false); + QVERIFY2(!w.handle(), "Hiding a non-created window doesn't create it"); + w.setVisible(true); + QVERIFY2(w.handle(), "Showing a non-created window creates it"); +} + void tst_QWindow::mapGlobal() { QWindow a;