summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/kernel/qlayout
diff options
context:
space:
mode:
authorThorbjørn Lund Martsum <tmartsum@gmail.com>2012-08-10 15:24:33 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-07-10 09:26:31 +0200
commit692e642305e2c24883645bd56db491d031e97252 (patch)
treeb1d5d522b9c50aa4b0bf99e2c2d8f05ac915176c /tests/auto/widgets/kernel/qlayout
parentc92d1d8acdfb125ce8abfcd996ac151437e6f31d (diff)
QSizePolicy - add retainSizeWhenHidden
Sometimes it is nice that hiding a widget does not affect the layout. This patch makes that possible by allowing hidden widgets to take up space. Change-Id: Ifbc1cdee0e112950acc025919b98199ea9558db7 Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com> Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'tests/auto/widgets/kernel/qlayout')
-rw-r--r--tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp b/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp
index 2b9b4fd761..ab2df2e250 100644
--- a/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp
+++ b/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp
@@ -84,6 +84,7 @@ private slots:
void controlTypes();
void controlTypes2();
void adjustSizeShouldMakeSureLayoutIsActivated();
+ void testRetainSizeWhenHidden();
};
tst_QLayout::tst_QLayout()
@@ -350,5 +351,47 @@ void tst_QLayout::adjustSizeShouldMakeSureLayoutIsActivated()
QCOMPARE(main.size(), QSize(200, 10));
}
+void tst_QLayout::testRetainSizeWhenHidden()
+{
+ QWidget widget;
+ QBoxLayout layout(QBoxLayout::TopToBottom, &widget);
+
+ QLabel *label1 = new QLabel("label1 text", &widget);
+ layout.addWidget(label1);
+ QLabel *label2 = new QLabel("label2 text", &widget);
+ layout.addWidget(label2);
+
+ widget.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
+ int normalHeight = widget.height();
+
+ // a. Verify that a removed visible will mean lesser size after adjust
+ label1->hide();
+ widget.adjustSize();
+ int heightWithoutLabel1 = widget.height();
+ QVERIFY(heightWithoutLabel1 < normalHeight);
+
+ // b restore with verify that the size is the same
+ label1->show();
+ QCOMPARE(widget.sizeHint().height(), normalHeight);
+
+ // c verify that a policy with retainSizeWhenHidden is respected
+ QSizePolicy sp_remove = label1->sizePolicy();
+ QSizePolicy sp_retain = label1->sizePolicy();
+ sp_retain.setRetainSizeWhenHidden(true);
+
+ label1->setSizePolicy(sp_retain);
+ label1->hide();
+ QCOMPARE(widget.sizeHint().height(), normalHeight);
+
+ // d check that changing the policy to not wanting size will result in lesser size
+ label1->setSizePolicy(sp_remove);
+ QCOMPARE(widget.sizeHint().height(), heightWithoutLabel1);
+
+ // e verify that changing back the hidden widget to want the hidden size will ensure that it gets more size
+ label1->setSizePolicy(sp_retain);
+ QCOMPARE(widget.sizeHint().height(), normalHeight);
+}
+
QTEST_MAIN(tst_QLayout)
#include "tst_qlayout.moc"