From e977b55346facf9238892a81ba2b2b382e6f46be Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 30 Nov 2021 20:30:47 +0100 Subject: [PATCH] QTabBar: clamp maxScrollOffset before using it in qBound QTabBar's test reveals that maxScrollOffset can be negative, so using it in a call like qBound(0, x, maxScrollOffset) is wrong. Clamp it to 0. Change-Id: Idd635343bf14c904dbcc4d141f10bd0161d2cfb4 Reviewed-by: Volker Hilsheimer --- src/widgets/widgets/qtabbar.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index 3fdd6fc3148..4b1a37d6e2d 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -2408,9 +2408,9 @@ void QTabBar::wheelEvent(QWheelEvent *event) if (!d->rightB->isVisible()) scrollRectExtent += tabsVertical ? d->rightB->height() : d->rightB->width(); - const int maxScrollOffset = (tabsVertical ? lastTabRect.bottom() - : lastTabRect.right()) - - scrollRectExtent; + const int maxScrollOffset = qMax((tabsVertical ? + lastTabRect.bottom() : + lastTabRect.right()) - scrollRectExtent, 0); d->scrollOffset = qBound(0, d->scrollOffset - delta, maxScrollOffset); d->leftB->setEnabled(d->scrollOffset > -scrollRect.left()); d->rightB->setEnabled(maxScrollOffset > d->scrollOffset);