@@ -100,6 +100,7 @@ private slots:
100
100
void resizeKeepsScroll ();
101
101
void changeTabTextKeepsScroll ();
102
102
void settingCurrentTabBeforeShowDoesntScroll ();
103
+ void checkScrollResetAfterTabRemoval ();
103
104
104
105
private:
105
106
void checkPositions (const TabBar &tabbar, const QList<int > &positions);
@@ -1482,5 +1483,50 @@ void tst_QTabBar::settingCurrentTabBeforeShowDoesntScroll()
1482
1483
QCOMPARE_GT (getScrollOffset (), 0 );
1483
1484
}
1484
1485
1486
+ void tst_QTabBar::checkScrollResetAfterTabRemoval ()
1487
+ {
1488
+ class TabWidget : public QTabWidget
1489
+ {
1490
+ public:
1491
+ using QTabWidget::QTabWidget;
1492
+ using QTabWidget::setTabBar;
1493
+ };
1494
+
1495
+ TabWidget tabWidget;
1496
+ QTabBar tabBar;
1497
+ tabBar.setUsesScrollButtons (true );
1498
+
1499
+ tabWidget.setTabBar (&tabBar);
1500
+ for (int i = 0 ; i < 6 ; ++i)
1501
+ tabWidget.addTab (new QWidget, u" Tab %1" _s.arg (i));
1502
+ tabWidget.setTabPosition (QTabWidget::North);
1503
+ tabWidget.setCurrentIndex (0 );
1504
+ tabWidget.show ();
1505
+ QVERIFY (QTest::qWaitForWindowExposed (&tabWidget));
1506
+
1507
+ QVERIFY (tabWidget.tabBar ()->tabRect (0 ).intersects (tabWidget.tabBar ()->rect ()));
1508
+ auto *rightButton = tabBar.findChild <QAbstractButton*>(u" ScrollRightButton" _s);
1509
+
1510
+ QVERIFY (rightButton);
1511
+ QVERIFY (rightButton->isEnabled ());
1512
+ // simulate a right button click to increase the scroll offset.
1513
+ for (int i = 0 ; i < 2 ; i++)
1514
+ rightButton->click ();
1515
+
1516
+ const auto getScrollOffset = [&]() -> int {
1517
+ return static_cast <QTabBarPrivate *>(QObjectPrivate::get (&tabBar))->scrollOffset ;
1518
+ };
1519
+
1520
+ // scroll offset is expected to be greater than 0.
1521
+ QCOMPARE_GT (getScrollOffset (), 0 );
1522
+
1523
+ QVERIFY (!tabWidget.tabBar ()->tabRect (0 ).intersects (tabWidget.tabBar ()->rect ()));
1524
+ // try removing the last tab and check if the scroll offset is reset to 0, to show the first tab.
1525
+ tabWidget.removeTab (5 );
1526
+
1527
+ // scroll offset is expected to be reset to 0.
1528
+ QCOMPARE (getScrollOffset (), 0 );
1529
+ }
1530
+
1485
1531
QTEST_MAIN (tst_QTabBar)
1486
1532
#include " tst_qtabbar.moc"
0 commit comments