Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QScrollBar acts differently when pressing arrow keys and scrolling.
Forum Update on Monday, May 27th 2025

QScrollBar acts differently when pressing arrow keys and scrolling.

Scheduled Pinned Locked Moved Solved General and Desktop
qscrollbarqscrollareaqslider
4 Posts 3 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tokafr
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by Chris Kawa
        #3

        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.

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

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

          T Offline
          T Offline
          tokafr
          wrote on last edited by
          #4

          @SGaist Thanks I managed to do it this way.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved