void setVisible(bool visible) {
if (!m_complete)
m_visible = visible;
- else
+ else if (!transientParent() || transientParent()->isVisible())
QQuickWindow::setVisible(visible);
}
void componentComplete() {
m_complete = true;
+ if (transientParent() && !transientParent()->isVisible()) {
+ connect(transientParent(), &QQuickWindow::visibleChanged, this,
+ &QQuickWindowQmlImpl::setWindowVisibility, Qt::QueuedConnection);
+ } else {
+ setWindowVisibility();
+ }
+ }
+
+private Q_SLOTS:
+ void setWindowVisibility()
+ {
+ if (transientParent() && !transientParent()->isVisible())
+ return;
+
+ if (sender()) {
+ disconnect(transientParent(), &QWindow::visibleChanged, this,
+ &QQuickWindowQmlImpl::setWindowVisibility);
+ }
// We have deferred window creation until we have the full picture of what
// the user wanted in terms of window state, geometry, visibility, etc.
--- /dev/null
+import QtQuick 2.1
+import QtQuick.Window 2.1
+
+Window {
+ id: window1;
+ objectName: "window1";
+ width: 100; height: 100;
+ visible: true
+ color: "blue"
+ property alias win2: window2
+ property alias win3: window3
+ property alias win4: window4
+ property alias win5: window5
+ Window {
+ id: window2;
+ objectName: "window2";
+ width: 100; height: 100;
+ visible: true
+ color: "green"
+ Window {
+ id: window3;
+ objectName: "window3";
+ width: 100; height: 100;
+ visible: true
+ }
+
+ Window { //Is invisible by default
+ id: window4
+ objectName: "window4";
+ height: 200
+ width: 200
+ color: "black"
+ Window {
+ id: window5
+ objectName: "window5";
+ height: 200
+ width: 200
+ visible: true
+ }
+ }
+ }
+}
void requestActivate();
+ void testWindowVisibilityOrder();
+
void blockClosing();
void crashWhenHoverItemDeleted();
QVERIFY(windows.at(0)->objectName() == "window2");
window1->show();
- window1->requestActivate();
+ QVERIFY(QTest::qWaitForWindowExposed(windows.at(0))); //We wait till window 2 comes up
+ window1->requestActivate(); // and then transfer the focus to window1
QTRY_VERIFY(QGuiApplication::focusWindow() == window1);
QVERIFY(window1->isActive() == true);
QTRY_VERIFY(QGuiApplication::focusWindow() == windows.at(0));
QVERIFY(windows.at(0)->isActive());
+ delete window1;
+}
+
+void tst_qquickwindow::testWindowVisibilityOrder()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.loadUrl(testFileUrl("windoworder.qml"));
+ QQuickWindow *window1 = qobject_cast<QQuickWindow *>(component.create());
+ QQuickWindow *window2 = window1->property("win2").value<QQuickWindow*>();
+ QQuickWindow *window3 = window1->property("win3").value<QQuickWindow*>();
+ QQuickWindow *window4 = window1->property("win4").value<QQuickWindow*>();
+ QQuickWindow *window5 = window1->property("win5").value<QQuickWindow*>();
+ QVERIFY(window1);
+ QVERIFY(window2);
+ QVERIFY(window3);
+
+ QTest::qWaitForWindowExposed(window3);
+
+ QWindowList windows = QGuiApplication::topLevelWindows();
+ QTRY_COMPARE(windows.size(), 5);
+
+ QVERIFY(window3 == QGuiApplication::focusWindow());
+ QVERIFY(window1->isActive());
+ QVERIFY(window2->isActive());
+ QVERIFY(window3->isActive());
+
+ //Test if window4 is shown 2 seconds after the application startup
+ //with window4 visible window5 (transient child) should also become visible
+ QVERIFY(!window4->isVisible());
+ QVERIFY(!window5->isVisible());
+
+ window4->setVisible(true);
+
+ QTest::qWaitForWindowExposed(window5);
+ QVERIFY(window4->isVisible());
+ QVERIFY(window5->isVisible());
+ window4->hide();
+ window5->hide();
+
+ window3->hide();
+#if defined(Q_OS_OSX)
+ QEXPECT_FAIL("","Focus is not transferred to transient parent on window close (QTBUG-33423)", Continue);
+#endif
+ QTRY_COMPARE(window2 == QGuiApplication::focusWindow(), true);
+
+ window2->hide();
+ QTRY_COMPARE(window1 == QGuiApplication::focusWindow(), true);
}
void tst_qquickwindow::blockClosing()