From 42d681f9cfc984046a93b9efe19903d46ac68bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Mon, 3 Sep 2012 06:35:39 +0200 Subject: Add widget replace function to QLayout Sometimes it is nice to be able to replace a widget in a layout. Change-Id: I23a6a65e417e94d53bc48639503db1a142bc3f10 Reviewed-by: J-P Nurmi --- .../widgets/kernel/qboxlayout/tst_qboxlayout.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tests/auto/widgets/kernel/qboxlayout') diff --git a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp index bdc32ba197..850bedd9cc 100644 --- a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp +++ b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp @@ -79,6 +79,7 @@ private slots: void taskQTBUG_7103_minMaxWidthNotRespected(); void taskQTBUG_27420_takeAtShouldUnparentLayout(); + void replaceWidget(); }; class CustomLayoutStyle : public QProxyStyle @@ -328,7 +329,6 @@ void tst_QBoxLayout::taskQTBUG_27420_takeAtShouldUnparentLayout() QVERIFY(!inner.isNull()); } - struct Descr { Descr(int min, int sh, int max = -1, bool exp= false, int _stretch = 0, bool _empty = false) @@ -507,5 +507,24 @@ void tst_QBoxLayout::testLayoutEngine() } } +void tst_QBoxLayout::replaceWidget() +{ + QWidget w; + QBoxLayout *boxLayout = new QVBoxLayout(&w); + + QLineEdit *replaceFrom = new QLineEdit; + QLineEdit *replaceTo = new QLineEdit; + boxLayout->addWidget(new QLineEdit()); + boxLayout->addWidget(replaceFrom); + boxLayout->addWidget(new QLineEdit()); + + QCOMPARE(boxLayout->indexOf(replaceFrom), 1); + QCOMPARE(boxLayout->indexOf(replaceTo), -1); + boxLayout->replaceWidget(replaceFrom, replaceTo); + + QCOMPARE(boxLayout->indexOf(replaceFrom), -1); + QCOMPARE(boxLayout->indexOf(replaceTo), 1); +} + QTEST_MAIN(tst_QBoxLayout) #include "tst_qboxlayout.moc" -- cgit v1.2.3