From 61e0fa5d689264fa776aab4e8f8cd5e6f7b458de Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 2 Nov 2012 17:19:59 +0100 Subject: Make it obvious that adding a QLayout to QSplitter is not supported. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It does not make sense to add a QLayout to a QSplitter, since the splitter manages its child widgets in the same manner as a QLayout. The result of doing so is that the child widgets inside that layout will lead to the splitter and the layout fighting to position the child widgets. QSplitter::addWidget should be used to add widgets directly to the splitter instead. Change-Id: I640b463cae8673f87354d28636bff4dd3cfb9679 Reviewed-by: Samu Voutilainen Reviewed-by: Samuel Rødal --- src/widgets/widgets/qsplitter.cpp | 9 ++++++++- tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp | 12 +++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp index 794a824589..bbd5695e9b 100644 --- a/src/widgets/widgets/qsplitter.cpp +++ b/src/widgets/widgets/qsplitter.cpp @@ -917,6 +917,10 @@ QSplitterLayoutStruct *QSplitterPrivate::insertWidget(int index, QWidget *w) When you hide() a child its space will be distributed among the other children. It will be reinstated when you show() it again. + \note Adding a QLayout to a QSplitter is not supported (either through + setLayout() or making the QSplitter a parent of the QLayout); use addWidget() + instead (see example above). + \sa QSplitterHandle, QHBoxLayout, QVBoxLayout, QTabWidget */ @@ -1207,8 +1211,11 @@ int QSplitter::count() const void QSplitter::childEvent(QChildEvent *c) { Q_D(QSplitter); - if (!c->child()->isWidgetType()) + if (!c->child()->isWidgetType()) { + if (c->type() == QEvent::ChildAdded && qobject_cast(c->child())) + qWarning("Adding a QLayout to a QSplitter is not supported."); return; + } QWidget *w = static_cast(c->child()); if (c->added() && !d->blockChildAdd && !w->isWindow() && !d->findWidget(w)) { d->insertWidget_helper(d->list.count(), w, false); diff --git a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp index 51132e2116..7f2033f527 100644 --- a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp +++ b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp @@ -93,7 +93,7 @@ private slots: void task169702_sizes(); void taskQTBUG_4101_ensureOneNonCollapsedWidget_data(); void taskQTBUG_4101_ensureOneNonCollapsedWidget(); - + void setLayout(); private: void removeThirdWidget(); void addThirdWidget(); @@ -770,5 +770,15 @@ void tst_QSplitter::taskQTBUG_4101_ensureOneNonCollapsedWidget() QVERIFY(s.sizes().at(0) > 0); } +void tst_QSplitter::setLayout() +{ + QSplitter splitter; + QVBoxLayout layout; + QTest::ignoreMessage(QtWarningMsg, "Adding a QLayout to a QSplitter is not supported."); + splitter.setLayout(&layout); + // It will work, but we don't recommend it... + QCOMPARE(splitter.layout(), &layout); +} + QTEST_MAIN(tst_QSplitter) #include "tst_qsplitter.moc" -- cgit v1.2.3