diff options
author | Thorbjørn Lund Martsum <tmartsum@gmail.com> | 2012-09-03 06:35:39 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-21 23:17:55 +0200 |
commit | 42d681f9cfc984046a93b9efe19903d46ac68bb1 (patch) | |
tree | 0a93a177458dc661b9ceb200f8fa21250b6b601f /tests/auto/widgets/kernel/qboxlayout | |
parent | e327ba191df56f3315a004d7650d5f1080f12acb (diff) |
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 <jpnurmi@digia.com>
Diffstat (limited to 'tests/auto/widgets/kernel/qboxlayout')
-rw-r--r-- | tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
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" |