From 06b1e404c936847038cc7a371720b05f31532b6a Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Sun, 6 Jun 2021 11:30:37 +0200 Subject: Fix scrolling of tab bar when the visible tab is wider than the visible space When finding the index we need to scroll to, use the one where both start and end of the tab rect are outside the currently visible section. Otherwise we wouldn't scroll when the left-most index ends outside the visible section. Add test, which requires that the scroll buttons have object names. Fixes: QTBUG-70498 Pick-to: 6.2 6.1 5.15 Change-Id: Id153c77dd5fca146612375e0ff39bd1f3e0536b1 Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qtabbar.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index a390f9ec0d..1e8403c66b 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -408,10 +408,12 @@ void QTabBarPrivate::init() { Q_Q(QTabBar); leftB = new QToolButton(q); + leftB->setObjectName(u"ScrollLeftButton"_qs); leftB->setAutoRepeat(true); QObject::connect(leftB, SIGNAL(clicked()), q, SLOT(_q_scrollTabs())); leftB->hide(); rightB = new QToolButton(q); + rightB->setObjectName(u"ScrollRightButton"_qs); rightB->setAutoRepeat(true); QObject::connect(rightB, SIGNAL(clicked()), q, SLOT(_q_scrollTabs())); rightB->hide(); @@ -824,21 +826,24 @@ void QTabBarPrivate::_q_scrollTabs() Q_Q(QTabBar); const QObject *sender = q->sender(); const bool horizontal = !verticalTabs(shape); - const QRect scrollRect = normalizedScrollRect(); + const QRect scrollRect = normalizedScrollRect().translated(scrollOffset, 0); + int i = -1; if (sender == leftB) { for (i = tabList.count() - 1; i >= 0; --i) { int start = horizontal ? tabList.at(i)->rect.left() : tabList.at(i)->rect.top(); - if (start < scrollRect.left() + scrollOffset) { + if (start < scrollRect.left()) { makeVisible(i); return; } } } else if (sender == rightB) { for (i = 0; i < tabList.count(); ++i) { - int end = horizontal ? tabList.at(i)->rect.right() : tabList.at(i)->rect.bottom(); - if (end > scrollRect.right() + scrollOffset) { + const auto tabRect = tabList.at(i)->rect; + int start = horizontal ? tabRect.left() : tabRect.top(); + int end = horizontal ? tabRect.right() : tabRect.bottom(); + if (end > scrollRect.right() && start > scrollOffset) { makeVisible(i); return; } -- cgit v1.2.3