diff options
-rw-r--r-- | src/gui/widgets/qsplitter.cpp | 17 | ||||
-rw-r--r-- | tests/auto/qsplitter/tst_qsplitter.cpp | 34 |
2 files changed, 49 insertions, 2 deletions
diff --git a/src/gui/widgets/qsplitter.cpp b/src/gui/widgets/qsplitter.cpp index e3121ae..520a802 100644 --- a/src/gui/widgets/qsplitter.cpp +++ b/src/gui/widgets/qsplitter.cpp @@ -360,13 +360,26 @@ void QSplitterPrivate::recalc(bool update) before a hidden widget must be hidden. */ bool first = true; + bool allInvisible = n != 0; for (int i = 0; i < n ; ++i) { QSplitterLayoutStruct *s = list.at(i); - s->handle->setHidden(first || s->widget->isHidden()); - if (!s->widget->isHidden()) + bool widgetHidden = s->widget->isHidden(); + if (allInvisible && !widgetHidden && !s->collapsed) + allInvisible = false; + s->handle->setHidden(first || widgetHidden); + if (!widgetHidden) first = false; } + if (allInvisible) + for (int i = 0; i < n ; ++i) { + QSplitterLayoutStruct *s = list.at(i); + if (!s->widget->isHidden()) { + s->collapsed = false; + break; + } + } + int fi = 2 * q->frameWidth(); int maxl = fi; int minl = fi; diff --git a/tests/auto/qsplitter/tst_qsplitter.cpp b/tests/auto/qsplitter/tst_qsplitter.cpp index cf16421..b832f3a 100644 --- a/tests/auto/qsplitter/tst_qsplitter.cpp +++ b/tests/auto/qsplitter/tst_qsplitter.cpp @@ -102,6 +102,8 @@ private slots: void task187373_addAbstractScrollAreas(); void task187373_addAbstractScrollAreas_data(); void task169702_sizes(); + void taskQTBUG_4101_ensureOneNonCollapsedWidget_data(); + void taskQTBUG_4101_ensureOneNonCollapsedWidget(); private: void removeThirdWidget(); @@ -1281,6 +1283,8 @@ class MyFriendlySplitter : public QSplitter public: MyFriendlySplitter(QWidget *parent = 0) : QSplitter(parent) {} void setRubberBand(int pos) { QSplitter::setRubberBand(pos); } + + friend class tst_QSplitter; }; void tst_QSplitter::rubberBandNotInSplitter() @@ -1403,5 +1407,35 @@ void tst_QSplitter::task169702_sizes() QCOMPARE(testW->size().height(), testW->minimumSizeHint().height()); } +void tst_QSplitter::taskQTBUG_4101_ensureOneNonCollapsedWidget_data() +{ + QTest::addColumn<bool>("testingHide"); + + QTest::newRow("last non collapsed hidden") << true; + QTest::newRow("last non collapsed deleted") << false; +} + +void tst_QSplitter::taskQTBUG_4101_ensureOneNonCollapsedWidget() +{ + QFETCH(bool, testingHide); + + MyFriendlySplitter s; + QLabel *l; + for (int i = 0; i < 5; ++i) { + l = new QLabel(QString("Label ") + QChar('A' + i)); + l->setAlignment(Qt::AlignCenter); + s.addWidget(l); + s.moveSplitter(0, i); // Collapse all the labels except the last one. + } + + s.show(); + if (testingHide) + l->hide(); + else + delete l; + QTest::qWait(100); + QVERIFY(s.sizes().at(0) > 0); +} + QTEST_MAIN(tst_QSplitter) #include "tst_qsplitter.moc" |