diff --git a/src/widgets/kernel/qwidget_qpa.cpp b/src/widgets/kernel/qwidget_qpa.cpp index f03d2bd204..a1a414e4f4 100644 --- a/src/widgets/kernel/qwidget_qpa.cpp +++ b/src/widgets/kernel/qwidget_qpa.cpp @@ -925,8 +925,13 @@ void QWidgetPrivate::createTLSysExtra() Q_Q(QWidget); extra->topextra->screenIndex = 0; extra->topextra->window = 0; - if (q->testAttribute(Qt::WA_NativeWindow) || q->isWindow()) + if (q->testAttribute(Qt::WA_NativeWindow) || q->isWindow()) { extra->topextra->window = new QWidgetWindow(q); + if (extra->minw || extra->minh) + extra->topextra->window->setMinimumSize(QSize(extra->minw, extra->minh)); + if (extra->maxw != QWIDGETSIZE_MAX || extra->maxh != QWIDGETSIZE_MAX) + extra->topextra->window->setMaximumSize(QSize(extra->maxw, extra->maxh)); + } } void QWidgetPrivate::deleteTLSysExtra() 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 4daeb6ceb6..bccd9a5951 100644 --- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp +++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp @@ -46,6 +46,8 @@ #include #include +#include +#include class tst_QWidget_window : public QWidget @@ -60,6 +62,8 @@ public slots: void cleanupTestCase(); private slots: + void tst_min_max_size(); + void tst_min_max_size_data(); void tst_move_show(); void tst_show_move(); void tst_show_move_hide_show(); @@ -85,6 +89,39 @@ void tst_QWidget_window::cleanupTestCase() { } +/* Test if the maximum/minimum size constraints + * are propagated from the widget to the QWidgetWindow + * independently of whether they were set before or after + * window creation (QTBUG-26745). */ + +void tst_QWidget_window::tst_min_max_size_data() +{ + QTest::addColumn("setMinMaxSizeBeforeShow"); + QTest::newRow("Set min/max size after show") << false; + QTest::newRow("Set min/max size before show") << true; +} + +void tst_QWidget_window::tst_min_max_size() +{ + QFETCH(bool, setMinMaxSizeBeforeShow); + const QSize minSize(300, 400); + const QSize maxSize(1000, 500); + QWidget w1; + (new QVBoxLayout(&w1))->addWidget(new QPushButton("Test")); + if (setMinMaxSizeBeforeShow) { + w1.setMinimumSize(minSize); + w1.setMaximumSize(maxSize); + } + w1.show(); + if (!setMinMaxSizeBeforeShow) { + w1.setMinimumSize(minSize); + w1.setMaximumSize(maxSize); + } + QVERIFY(QTest::qWaitForWindowExposed(&w1)); + QCOMPARE(w1.windowHandle()->minimumSize(),minSize); + QCOMPARE(w1.windowHandle()->maximumSize(), maxSize); +} + void tst_QWidget_window::tst_move_show() { QWidget w;