diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-05-15 17:34:38 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-05-15 21:07:41 +0000 |
commit | 802eb09da77412010e47ab5c604fed29e8a520cb (patch) | |
tree | edb04a2d7fc019d4d9b72f5d0ba651cab3339d4e /tests | |
parent | 916b4d521b439135fb43424b96978332912fc85d (diff) |
QTabBar: Add testcase for tabs not scrolling
Verify that changing a tab's text doesn't scroll.
Fixes: QTBUG-45381
Task-number: QTBUG-113140
Change-Id: I02ace9d3fcaa20d8ff5d87ccca5d96a4114b0fb0
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
(cherry picked from commit c113a7a7969781877acfe30eb8e20c66f69f94f0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp index 7d47b744b1..6d5be7d558 100644 --- a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp +++ b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp @@ -98,6 +98,7 @@ private slots: void resizeKeepsScroll_data(); void resizeKeepsScroll(); + void changeTabTextKeepsScroll(); private: void checkPositions(const TabBar &tabbar, const QList<int> &positions); @@ -1426,5 +1427,30 @@ void tst_QTabBar::resizeKeepsScroll() } } +void tst_QTabBar::changeTabTextKeepsScroll() +{ + QTabBar tabBar; + TabBarScrollingProxyStyle proxyStyle; + tabBar.setStyle(&proxyStyle); + + for (int i = 0; i < 6; ++i) + tabBar.addTab(u"Tab Number %1"_s.arg(i)); + + const QSize fullSize = tabBar.sizeHint(); + tabBar.resize(fullSize.width() / 2, fullSize.height()); + + tabBar.show(); + QVERIFY(QTest::qWaitForWindowExposed(&tabBar)); + + const auto getScrollOffset = [&]() -> int { + return static_cast<QTabBarPrivate *>(QObjectPrivate::get(&tabBar))->scrollOffset; + }; + + tabBar.setCurrentIndex(3); + const int scrollOffset = getScrollOffset(); + tabBar.setTabText(3, "New title"); + QCOMPARE(getScrollOffset(), scrollOffset); +} + QTEST_MAIN(tst_QTabBar) #include "tst_qtabbar.moc" |