diff options
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 13 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 31 |
2 files changed, 37 insertions, 7 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index ec2e3e7367..f55e7f0803 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -612,20 +612,19 @@ void QWindow::setParent(QWindow *parent) } QObject::setParent(parent); + d->parentWindow = parent; + if (parent) d->disconnectFromScreen(); else d->connectToScreen(newScreen); if (d->platformWindow) { - if (parent && parent->d_func()->platformWindow) { - d->platformWindow->setParent(parent->d_func()->platformWindow); - } else { - d->platformWindow->setParent(0); - } - } + if (parent) + parent->create(); - d->parentWindow = parent; + d->platformWindow->setParent(parent ? parent->d_func()->platformWindow : 0); + } QGuiApplicationPrivate::updateBlockedStatus(this); } diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 71ff9aaf42..6f8fa3fcd1 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -59,6 +59,7 @@ class tst_QWindow: public QObject private slots: void create(); + void setParent(); void eventOrderOnShow(); void resizeEventAfterResize(); void mapGlobal(); @@ -155,6 +156,36 @@ void tst_QWindow::create() QVERIFY2(f.handle() == platformWindow, "Creating a child window should not affect parent if already created"); } +void tst_QWindow::setParent() +{ + QWindow a; + QWindow b(&a); + QVERIFY2(b.parent() == &a, "Setting parent at construction time should work"); + QVERIFY2(a.children().contains(&b), "Parent should have child in list of children"); + + QWindow c; + QWindow d; + d.setParent(&c); + QVERIFY2(d.parent() == &c, "Setting parent after construction should work"); + QVERIFY2(c.children().contains(&d), "Parent should have child in list of children"); + + a.create(); + b.setParent(0); + QVERIFY2(!b.handle(), "Making window top level shouild not automatically create it"); + + QWindow e; + c.create(); + e.setParent(&c); + QVERIFY2(!e.handle(), "Making window a child of a created window should not automatically create it"); + + QWindow f; + QWindow g; + g.create(); + QVERIFY(g.handle()); + g.setParent(&f); + QVERIFY2(f.handle(), "Making a created window a child of a non-created window should automatically create it"); +} + void tst_QWindow::mapGlobal() { QWindow a; |