summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-01-15 15:00:01 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-01-15 18:05:19 +0100
commit7f5d41e286e043c5f3061e2eb5a0128102a38c80 (patch)
tree492eb2a96fefbb2b24d00c85e19609216dc4b7b5
parent98a89fb711a15fcf9f541f7b4a8ae7492e5a445c (diff)
Windows: Fix dialog moving up after closing/reshowing
A resize event delivered after closing the platform window was causing the stored frame margins to be cleared. Bail out of QWidgetWindow::updateMargins() if the platform window is null. Pick-to: 5.15 Fixes: QTBUG-79147 Change-Id: Iebbc90c3cccafa209cd720baedf45affb3f3c2b8 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--src/widgets/kernel/qwidgetwindow.cpp6
-rw-r--r--tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp22
2 files changed, 27 insertions, 1 deletions
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index ae1e461d7a..cdc358aca2 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -736,8 +736,12 @@ bool QWidgetWindow::updateSize()
void QWidgetWindow::updateMargins()
{
- const QMargins margins = frameMargins();
+ // QTBUG-79147 (Windows): Bail out on resize events after closing a dialog
+ // and destroying the platform window which would clear the margins.
QTLWExtra *te = m_widget->d_func()->topData();
+ if (te->window == nullptr || te->window->handle() == nullptr)
+ return;
+ const QMargins margins = frameMargins();
te->posIncludesFrame= false;
te->frameStrut.setCoords(margins.left(), margins.top(), margins.right(), margins.bottom());
m_widget->data->fstrut_dirty = false;
diff --git a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp
index 9ef64480d6..53c33255bf 100644
--- a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp
+++ b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp
@@ -80,6 +80,7 @@ private slots:
void transientParent_data();
void transientParent();
void dialogInGraphicsView();
+ void keepPositionOnClose();
};
// Testing get/set functions
@@ -543,5 +544,26 @@ void tst_QDialog::dialogInGraphicsView()
}
}
+// QTBUG-79147 (Windows): Closing a dialog by clicking the 'X' in the title
+// bar would offset the dialog position when shown next time.
+void tst_QDialog::keepPositionOnClose()
+{
+ QDialog dialog;
+ dialog.setWindowTitle(QTest::currentTestFunction());
+ const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
+ dialog.resize(availableGeometry.size() / 4);
+ const QPoint pos = availableGeometry.topLeft() + QPoint(100, 100);
+ dialog.move(pos);
+ dialog.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&dialog));
+ dialog.close();
+ dialog.windowHandle()->destroy(); // Emulate a click on close by destroying the window.
+ QTest::qWait(50);
+ dialog.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&dialog));
+ QTest::qWait(50);
+ QCOMPARE(dialog.pos(), pos);
+}
+
QTEST_MAIN(tst_QDialog)
#include "tst_qdialog.moc"