Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved QScrollBar acts differently when pressing arrow keys and scrolling.

    General and Desktop
    qscrollbar qscrollarea qslider
    3
    4
    1654
    Loading More Posts
    • 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
      tokafr last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • Chris Kawa
          Chris Kawa Moderators last edited by Chris Kawa

          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 Reply Quote 0
          • T
            tokafr @SGaist last edited by

            @SGaist Thanks I managed to do it this way.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post