summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-11-22 19:24:42 +0100
committerAxel Spoerl <axel.spoerl@qt.io>2023-11-23 11:41:26 +0000
commit1082038bd89d0bbba4df0d9b3f8af3cd0a2f96f2 (patch)
tree7b21072f5b9e55a3d40a4dbb62f73cc386018b04 /tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp
parentfa045a3ce76d51dfa679945e74d9e2a685e14597 (diff)
QTabBar: properly calc tab positions when changing tab position
When changing the tab position, the scroll offset is calculated wrongly because the calculation is done before the size of the tabbar is recalculated. Therefore wait until QTabBar gets the resize event and calculate the new tab positions there. Pick-to: 6.6 6.5 Fixes: QTBUG-119366 Change-Id: I261a91bb584409b9b0dac4339a32894f47540bcf Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp')
-rw-r--r--tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp
index 7aede22441..2e6ae0c4cd 100644
--- a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp
+++ b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp
@@ -101,6 +101,7 @@ private slots:
void resizeKeepsScroll();
void changeTabTextKeepsScroll();
void settingCurrentTabBeforeShowDoesntScroll();
+ void checkPositionsAfterShapeChange();
private:
void checkPositions(const TabBar &tabbar, const QList<int> &positions);
@@ -1502,5 +1503,45 @@ void tst_QTabBar::settingCurrentTabBeforeShowDoesntScroll()
QCOMPARE_GT(getScrollOffset(), 0);
}
+void tst_QTabBar::checkPositionsAfterShapeChange()
+{
+ class TabWidget : public QTabWidget
+ {
+ public:
+ using QTabWidget::QTabWidget;
+ using QTabWidget::setTabBar;
+ };
+
+ class TabBar : public QTabBar
+ {
+ public:
+ using QTabBar::initStyleOption;
+ void resizeEvent(QResizeEvent *e) override
+ {
+ QTabBar::resizeEvent(e);
+ resized = true;
+ }
+ bool resized = false;
+ };
+
+ TabWidget tabWidget;
+ auto *tabBar = new TabBar;
+ tabWidget.setTabBar(tabBar);
+ for (int i = 0; i < 3; ++i)
+ tabWidget.addTab(new QWidget, u"Tab %1"_s.arg(i));
+ tabWidget.setTabPosition(QTabWidget::North);
+ tabWidget.setCurrentIndex(2);
+ tabWidget.resize(300, 300);
+ tabWidget.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&tabWidget));
+
+ tabBar->resized = false;
+ tabWidget.setTabPosition(QTabWidget::East);
+ QVERIFY(QTest::qWaitFor([&]() { return tabBar->resized; }));
+ QStyleOptionTab opt;
+ tabBar->initStyleOption(&opt, 2);
+ QVERIFY(opt.rect.top() > 0);
+}
+
QTEST_MAIN(tst_QTabBar)
#include "tst_qtabbar.moc"