Propagate initial size constraints to QWidgetWindow.

Size constraints set on a widget before the creation of
the QWidgetWindow were lost (for example, Qt Creator's
preference page).

Task-number: QTBUG-26745
Change-Id: I7c2f5aed9c8817795603e5ad3c24418d66627bab
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
Friedemann Kleint 2012-08-20 16:38:05 +02:00 committed by Qt by Nokia
parent 8133af2503
commit 82860b133c
2 changed files with 43 additions and 1 deletions

View File

@ -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()

View File

@ -46,6 +46,8 @@
#include <qlist.h>
#include <qlistwidget.h>
#include <qpushbutton.h>
#include <qboxlayout.h>
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<bool>("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;