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 <volker.hilsheimer@qt.io>
bb10
Giuseppe D'Angelo 2021-11-30 20:30:47 +01:00
parent d281274c3f
commit e977b55346
1 changed files with 3 additions and 3 deletions

View File

@ -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);