Scrollbar snapping


#1

hi,

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);
setSingleStepSize(1);

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


#2

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.


#3

…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.


#4

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.


#5

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.


#6

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.


#7

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.


#8

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.


#9