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>
This commit is contained in:
Volker Hilsheimer 2023-05-15 17:34:38 +02:00
parent 48b6c8503a
commit c113a7a796

View File

@ -98,6 +98,7 @@ private slots:
void resizeKeepsScroll_data(); void resizeKeepsScroll_data();
void resizeKeepsScroll(); void resizeKeepsScroll();
void changeTabTextKeepsScroll();
private: private:
void checkPositions(const TabBar &tabbar, const QList<int> &positions); 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) QTEST_MAIN(tst_QTabBar)
#include "tst_qtabbar.moc" #include "tst_qtabbar.moc"