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.5 Fixes: QTBUG-119366 Change-Id: I261a91bb584409b9b0dac4339a32894f47540bcf Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit 1082038bd89d0bbba4df0d9b3f8af3cd0a2f96f2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
3bdf033458
commit
b141b20668
@ -831,14 +831,9 @@ void QTabBarPrivate::refresh()
|
||||
pressedIndex = -1;
|
||||
}
|
||||
|
||||
if (!q->isVisible()) {
|
||||
layoutDirty = true;
|
||||
} else {
|
||||
layoutTabs();
|
||||
makeVisible(currentIndex);
|
||||
layoutDirty = true;
|
||||
if (q->isVisible())
|
||||
q->update();
|
||||
q->updateGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user