diff options
author | David Faure <faure@kde.org> | 2010-04-28 09:06:15 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-04-28 09:11:10 (GMT) |
commit | 89db625958949cf94f112fc2f9e6a3bf6399e43b (patch) | |
tree | fc3f2613aeeb034674d53db6f08a478c7d1f0a9f /tests/auto/qtabbar | |
parent | b4ce1496d6fcd54ae4ec2fed23bc0fddcd5bee33 (diff) | |
download | Qt-89db625958949cf94f112fc2f9e6a3bf6399e43b.zip Qt-89db625958949cf94f112fc2f9e6a3bf6399e43b.tar.gz Qt-89db625958949cf94f112fc2f9e6a3bf6399e43b.tar.bz2 |
QTabBar: smaller minimumSizeHint in ElideMode, and unit-test.
When a tabbar had a large number of tabs with short text
(5 to 7 characters), no eliding would happen, the window would keep
growing until it became wider than the desktop. This commit therefore
reduces the minimumSizeHint using more aggressive eliding when eliding
is enabled.
Also, at some point I had doubts about whether minimumSizeHint took
eliding into consideration at all, so I also added a unit-test for
minimumSizeHint and sizeHint of tabbars, in various modes.
Merge-request: 583
Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
Diffstat (limited to 'tests/auto/qtabbar')
-rw-r--r-- | tests/auto/qtabbar/tst_qtabbar.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/qtabbar/tst_qtabbar.cpp b/tests/auto/qtabbar/tst_qtabbar.cpp index 72f9dd3..28bed6b 100644 --- a/tests/auto/qtabbar/tst_qtabbar.cpp +++ b/tests/auto/qtabbar/tst_qtabbar.cpp @@ -76,6 +76,7 @@ private slots: void setElideMode_data(); void setElideMode(); + void sizeHints(); void setUsesScrollButtons_data(); void setUsesScrollButtons(); @@ -278,6 +279,45 @@ void tst_QTabBar::setElideMode() QTEST(int(tabBar.elideMode()), "expectedMode"); } +void tst_QTabBar::sizeHints() +{ + QTabBar tabBar; + tabBar.setFont(QFont("Arial", 10)); + tabBar.addTab("tab 01"); + tabBar.addTab("tab 02"); + tabBar.addTab("tab 03"); + tabBar.addTab("tab 04"); + tabBar.addTab("tab 05"); + tabBar.addTab("tab 06"); + tabBar.addTab("This is tab7"); + tabBar.addTab("This is tab8"); + tabBar.addTab("This is tab9 with a very long title"); + + // No eliding and no scrolling -> tabbar becomes very wide + tabBar.setUsesScrollButtons(false); + tabBar.setElideMode(Qt::ElideNone); +// qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint(); + QVERIFY(tabBar.minimumSizeHint().width() > 700); + QVERIFY(tabBar.sizeHint().width() > 700); + + // Scrolling enabled -> no reason to become very wide + tabBar.setUsesScrollButtons(true); + // qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint(); + QVERIFY(tabBar.minimumSizeHint().width() < 200); + QVERIFY(tabBar.sizeHint().width() > 700); // unchanged + + // Eliding enabled -> no reason to become very wide + tabBar.setUsesScrollButtons(false); + tabBar.setElideMode(Qt::ElideRight); +// qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint(); + QVERIFY(tabBar.minimumSizeHint().width() < 500); + QVERIFY(tabBar.sizeHint().width() > 700); // unchanged + + tabBar.addTab("This is tab10 with a very long title"); + QVERIFY(tabBar.minimumSizeHint().width() < 600); + QVERIFY(tabBar.sizeHint().width() > 700); // unchanged +} + void tst_QTabBar::setUsesScrollButtons_data() { QTest::addColumn<int>("usesArrows"); |