Skip to content

Commit

Permalink
QTabBar: clamp maxScrollOffset before using it in qBound
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dangelog committed Dec 1, 2021
1 parent d281274 commit e977b55
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/widgets/widgets/qtabbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e977b55

Please sign in to comment.