QScrollBar acts differently when pressing arrow keys and scrolling.



  • Hello
    I have a QScrollArea where I have set widget with layout.
    the problem is that, then I set verticalScrollBar() -> setSingleStep(step); it scrolls with this value when pressing arrow keys but mouse scrolling scrolls it with different value. How should I connect this 2 way to scroll with the same value? I am using Qt 4.8 version.

    thanks.


  • Lifetime Qt Champion

    Hi,

    You'll likely have to re-implement the wheelEvent function in a QScrollBar subclass to do what you want.


  • Moderators

    A user can change the "amount of scrolling" on a system level and different mices can scroll by different steps.

    A simplified formula for how Qt calculates the amount of wheel scroll is:
    scrollbar->singleStep() * QApplication::wheelScrollLines() * delta / 120
    and that is then truncated to the scrollbar->pageStep() value if necessary.

    You can control two of these values - the single step and wheel scroll lines. Delta is device dependent and 120 is a magic value. Qt also does some logic for cases when this formula results in fractions i.e. it carries them over to the next event.

    For most "regular" mices setting single step and wheel scroll lines to 1 should result in behavior you're after.



  • @SGaist Thanks I managed to do it this way.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.