From c113a7a7969781877acfe30eb8e20c66f69f94f0 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 15 May 2023 17:34:38 +0200 Subject: [PATCH] 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 Reviewed-by: Santhosh Kumar --- .../widgets/widgets/qtabbar/tst_qtabbar.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) 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 &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(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"