Scrollbar snapping



is there a way to make sure that when drag or mouse-scroll the ScrollBar is snapped using the value specified by setSingleStepSize()?

I have the following code:

setRangeLimits(0, numSteps);
setCurrentRange(0, 8);

It already works when using arrows or dragging withouth clicking on the thumb area, but not in other situations


I suppose it would need another setting for that, and probably a different value to the single-step size, as you might actually want them to be different.


…though personally, I’d probably do the snapping separately from the scrollbar. It looks a bit nicer to keep the scrollbar motion smooth, and snap the items that it’s adjusting. Like the scrollbars on iTunes.


how would you snap to let’s say chunks of 20pixels with a viewport for example?

I have:

but it only works when clicking arrow buttons, not mouse scroll or mouse drag.


ah yes, with a viewport of course you’ve not got control over that…

TBH I’m not sure whether the snapping would “belong” in the VP or the scrollbar in that case.


as you’ve said I think the snapping handling should belong to the viewport I already do it in a custom component that uses a scrollbar directly to switch between pages.

however having an extra option to quantize the display position could also be useful.


Is there a way to set a scrollbar to work in integers?

Ex. Set scrollbar range to be 1-9, have the arrow buttons increase/decrease by 1, and the paging increase/decrease by 3.


Always better to leave your scrollbar position as a double, and snap your content instead. You need to consider what happens with continuous or inertial scroll wheels, etc.