Add ScrollHandler
Features:
- Management of a Flickable, a vertical ScrollBar and a horizontal ScrollBar.
- A Flickable has to be set for it to do anything useful, but it shouldn't cause segfaults at least.
- ScrollHandler doesn't need scrollbars to be set for it to work well by default, it just manages the interactive state of the scrollbars and manages wheel and key events for them.
- The ability to set the step size as a number of pixels or as a percent of the content width/height.
- This is also helpful for views that need to scroll precisely by a specific amount of items. All you need to do is calculate the amount of pixels correctly.
- The ability to filter mouse and key events like a ScrollView without actually having to use a ScrollView.
- PageUp, PageDown, Home and End key support
- Default scrolling that is more consistent with Qt Widgets apps (QScrollArea).
- Slots for scrolling a specific amount of pixels in a specific direction and they return a bool for whether or not scrolling actually happened. Works nicely with
Keys
signal handlers. - A
scrolling
property with a configurable delay before it's set to false. We can use this to do things like disable wheel input for controls while the view is scrolling. - Page scrolling with a touchpad is smoother and easier to control.
- The keyboard modifiers for page scrolling and horizontal scrolling can be customized.
This based on Kirigami WheelHandler, but I didn't modify WheelHandler because I wanted to make some changes that could break apps that rely on existing WheelHandler behavior. This also seemed like a good opportunity to use a more descriptive class name since WheelHandler is really just for handling scrolling. Qt Quick WheelHandler is better for general wheel handling and having a Kirigami WheelHandler and a Qt Quick WheelHandler is slightly confusing.
TL;DR for major differences from Kirigami WheelHandler
- WheelHandler uses
angleDelta / 8 * wheelScrollLines
as the mouse wheel scrolling increment, which makes it different from every other default scrolling increment used by Qt Widgets apps (20 * wheelScrollLines
for QScrollArea/QTextEdit orviewportSize / 20 * wheelScrollLines
for QGraphicsView), GTK apps (viewportSize^(2/3)
) and some Electron apps/Chromium (hardcoded53
, yes really).- For most mouse wheels, mouse wheel notches are 120 angleDelta units each and wheelScrollLines is 3 by default, so
angleDelta / 8 * wheelScrollLines
is 45px. Noticeably slower than most apps.
- For most mouse wheels, mouse wheel notches are 120 angleDelta units each and wheelScrollLines is 3 by default, so
- WheelHandler doesn't allow horizontal scrolling with a mouse wheel unless you can't scroll vertically.
- WheelHandler can't be configured to scroll in such a way that items in the view line up perfectly with the scrolling increments.
- WheelHandler can't be configured to scroll a percent of the content area.
- WheelHandler doesn't have the option to handle mouse or key events.
- ScrollHandler doesn't have
blockTargetWheel
orscrollFlickableTarget
properties because they're not necessary.
Edited by Noah Davis