From b65e30c861af308d142c36b5f96f1a4cfedde1f3 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 12 Jun 2017 16:55:03 -0700 Subject: QWidget: Call appropriate QWindow method from setGeometry_sys() When calling resize() from showEvent(), we'd set the full geometry on the widget's QWindow. This resulted in the top-level window being moved to the top-left corner, even though no other call to move() or setGeometry() had happened before. The solution consists on calling the proper QWindow methods depending on whether setGeometry_sys() is called for a move, a resize or both. Furthermore, this needs QWindow::resize() to set its position policy to frame-exclusive. The documentation states that is already the case and we're setting the full geometry on the platform window, so we need to convey that bit of information. This also solves the age-old conundrum: "### why do we have isMove as a parameter?" Change-Id: I2e00fd632929ade14b35ae5e6495ed1ab176d32f Task-number: QTBUG-56277 Reviewed-by: Gabriel de Dietrich Reviewed-by: Friedemann Kleint --- .../kernel/qwidget_window/tst_qwidget_window.cpp | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp') diff --git a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp index 6aaac6d135..f20978c295 100644 --- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp +++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp @@ -99,6 +99,8 @@ private slots: void tst_eventfilter_on_toplevel(); void QTBUG_50561_QCocoaBackingStore_paintDevice_crash(); + + void QTBUG_56277_resize_on_showEvent(); }; void tst_QWidget_window::initTestCase() @@ -861,5 +863,34 @@ void tst_QWidget_window::QTBUG_50561_QCocoaBackingStore_paintDevice_crash() w.close(); } +class ResizedOnShowEventWidget : public QWidget +{ +public: + void showEvent(QShowEvent *) override + { + const auto *primaryScreen = QApplication::primaryScreen(); + auto newSize = primaryScreen->availableGeometry().size() / 4; + if (newSize == geometry().size()) + newSize -= QSize(10, 10); + resize(newSize); + } +}; + +void tst_QWidget_window::QTBUG_56277_resize_on_showEvent() +{ + const auto platformName = QGuiApplication::platformName().toLower(); + if (platformName != "cocoa" && platformName != "windows") + QSKIP("This can only be consistently tested on desktop platforms with well-known behavior."); + + ResizedOnShowEventWidget w; + w.show(); + QVERIFY(QTest::qWaitForWindowExposed(&w)); + const auto *screen = w.windowHandle()->screen(); + const auto geometry = w.geometry(); + const int frameHeight = geometry.top() - w.frameGeometry().top(); + const int topmostY = screen->availableGeometry().top() + frameHeight; + QVERIFY(geometry.top() > topmostY || geometry.left() > screen->availableGeometry().left()); +} + QTEST_MAIN(tst_QWidget_window) #include "tst_qwidget_window.moc" -- cgit v1.2.3