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 <Friedemann.Kleint@qt.io>
This commit is contained in:
Tor Arne Vestbø 2017-02-10 15:57:11 +01:00
parent 9bf8cc1f18
commit 09e7a994d1
2 changed files with 16 additions and 2 deletions

View File

@ -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;

View File

@ -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;