diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-05-15 17:34:38 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-05-15 21:03:00 +0200 |
commit | c113a7a7969781877acfe30eb8e20c66f69f94f0 (patch) | |
tree | 113a16939fc507a32affd4c72e202049c962e6ea | |
parent | 48b6c8503ae92a0480f8a1a63d979e689ae34a80 (diff) | |
download | qtbase-c113a7a7969781877acfe30eb8e20c66f69f94f0.tar.gz |
QTabBar: Add testcase for tabs not scrolling
Verify that changing a tab's text doesn't scroll.
Fixes: QTBUG-45381
Task-number: QTBUG-113140
Pick-to: 6.5
Change-Id: I02ace9d3fcaa20d8ff5d87ccca5d96a4114b0fb0
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
-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" |