summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-02-17 20:46:33 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-03-07 18:36:06 +0000
commitb64f3f6ca97e299176ca8990402650552a90f704 (patch)
tree5018cbe1bf3f76e07772bd16268ed5b0ac8a179e
parent3185b40d5de1092ed2bdd83f72478a344c5fc9e9 (diff)
QTabWidget: Do not add tabbar size during sizeHint() when it is hidden
Since Qt 5.4 the QTabBar can be automatically hidden when it has less then 2 tabs. Therefore the sizeHint should not consider the tabbars size when the tabbar is hidden. Task-number: QTBUG-64715 Change-Id: I2f248f88d9070de5354f7344c7628a78442ab499 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--src/widgets/widgets/qtabwidget.cpp36
-rw-r--r--tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp29
2 files changed, 53 insertions, 12 deletions
diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp
index 60a924510a..894053ec19 100644
--- a/src/widgets/widgets/qtabwidget.cpp
+++ b/src/widgets/widgets/qtabwidget.cpp
@@ -195,6 +195,11 @@ public:
void _q_removeTab(int);
void _q_tabMoved(int from, int to);
void init();
+ bool isAutoHidden() const
+ {
+ // see QTabBarPrivate::autoHideTabs()
+ return (tabs->autoHide() && tabs->count() <= 1);
+ }
void initBasicStyleOption(QStyleOptionTabWidgetFrame *option) const;
@@ -841,11 +846,14 @@ QSize QTabWidget::sizeHint() const
that->setUpLayout(true);
}
QSize s(d->stack->sizeHint());
- QSize t(d->tabs->sizeHint());
- if(usesScrollButtons())
- t = t.boundedTo(QSize(200,200));
- else
- t = t.boundedTo(QDesktopWidgetPrivate::size());
+ QSize t;
+ if (!d->isAutoHidden()) {
+ t = d->tabs->sizeHint();
+ if (usesScrollButtons())
+ t = t.boundedTo(QSize(200,200));
+ else
+ t = t.boundedTo(QDesktopWidgetPrivate::size());
+ }
QSize sz = basicSize(d->pos == North || d->pos == South, lc, rc, s, t);
@@ -873,7 +881,9 @@ QSize QTabWidget::minimumSizeHint() const
that->setUpLayout(true);
}
QSize s(d->stack->minimumSizeHint());
- QSize t(d->tabs->minimumSizeHint());
+ QSize t;
+ if (!d->isAutoHidden())
+ t = d->tabs->minimumSizeHint();
QSize sz = basicSize(d->pos == North || d->pos == South, lc, rc, s, t);
@@ -908,12 +918,14 @@ int QTabWidget::heightForWidth(int width) const
QTabWidget *that = const_cast<QTabWidget*>(this);
that->setUpLayout(true);
}
- QSize t(d->tabs->sizeHint());
-
- if(usesScrollButtons())
- t = t.boundedTo(QSize(200,200));
- else
- t = t.boundedTo(QDesktopWidgetPrivate::size());
+ QSize t;
+ if (!d->isAutoHidden()) {
+ t = d->tabs->sizeHint();
+ if (usesScrollButtons())
+ t = t.boundedTo(QSize(200,200));
+ else
+ t = t.boundedTo(QDesktopWidgetPrivate::size());
+ }
const bool tabIsHorizontal = (d->pos == North || d->pos == South);
const int contentsWidth = width - padding.width();
diff --git a/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp b/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp
index 2a2331c3bf..b5ffb90e42 100644
--- a/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp
+++ b/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp
@@ -98,6 +98,7 @@ private slots:
void heightForWidth();
void tabBarClicked();
void moveCurrentTab();
+ void autoHide();
private:
int addPage();
@@ -713,5 +714,33 @@ void tst_QTabWidget::moveCurrentTab()
QCOMPARE(tabWidget.currentWidget(), secondTab);
}
+void tst_QTabWidget::autoHide()
+{
+ QTabWidget tabWidget;
+ QWidget* firstTab = new QWidget(&tabWidget);
+ tabWidget.addTab(firstTab, "0");
+ const auto sizeHint1 = tabWidget.sizeHint();
+ const auto minSizeHint1 = tabWidget.minimumSizeHint();
+ const auto heightForWidth1 = tabWidget.heightForWidth(20);
+
+ QWidget* secondTab = new QWidget(&tabWidget);
+ tabWidget.addTab(secondTab, "1");
+ const auto sizeHint2 = tabWidget.sizeHint();
+ const auto minSizeHint2 = tabWidget.minimumSizeHint();
+ const auto heightForWidth2 = tabWidget.heightForWidth(20);
+
+ tabWidget.setTabBarAutoHide(true);
+ // size should not change
+ QCOMPARE(sizeHint2, tabWidget.sizeHint());
+ QCOMPARE(minSizeHint2, tabWidget.minimumSizeHint());
+ QCOMPARE(heightForWidth2, tabWidget.heightForWidth(20));
+
+ tabWidget.removeTab(1);
+ // this size should change now since the tab should be hidden
+ QVERIFY(sizeHint1.height() > tabWidget.sizeHint().height());
+ QVERIFY(minSizeHint1.height() > tabWidget.sizeHint().height());
+ QVERIFY(heightForWidth1 > tabWidget.heightForWidth(20));
+}
+
QTEST_MAIN(tst_QTabWidget)
#include "tst_qtabwidget.moc"