WheelHandler

Search for usage in LXR

#include <wheelhandler.h>

Inheritance diagram for WheelHandler:

Properties

bool blockTargetWheel
 
bool filterMouseEvents
 
qreal horizontalStepSize
 
bool keyNavigationEnabled
 
Qt::KeyboardModifiers pageScrollModifiers
 
bool scrollFlickableTarget
 
QQuickItem target
 
qreal verticalStepSize
 
- Properties inherited from QObject
 objectName
 

Signals

void blockTargetWheelChanged ()
 
void filterMouseEventsChanged ()
 
void horizontalStepSizeChanged ()
 
void keyNavigationEnabledChanged ()
 
void pageScrollModifiersChanged ()
 
void scrollFlickableTargetChanged ()
 
void targetChanged ()
 
void verticalStepSizeChanged ()
 
void wheel (KirigamiWheelEvent *wheel)
 

Public Member Functions

 WheelHandler (QObject *parent=nullptr)
 
bool filterMouseEvents () const
 
qreal horizontalStepSize () const
 
bool keyNavigationEnabled () const
 
Qt::KeyboardModifiers pageScrollModifiers () const
 
void resetHorizontalStepSize ()
 
void resetPageScrollModifiers ()
 
void resetVerticalStepSize ()
 
Q_INVOKABLE bool scrollDown (qreal stepSize=-1)
 
Q_INVOKABLE bool scrollLeft (qreal stepSize=-1)
 
Q_INVOKABLE bool scrollRight (qreal stepSize=-1)
 
Q_INVOKABLE bool scrollUp (qreal stepSize=-1)
 
void setFilterMouseEvents (bool enabled)
 
void setHorizontalStepSize (qreal stepSize)
 
void setKeyNavigationEnabled (bool enabled)
 
void setPageScrollModifiers (Qt::KeyboardModifiers modifiers)
 
void setTarget (QQuickItem *target)
 
void setVerticalStepSize (qreal stepSize)
 
QQuickItemtarget () const
 
qreal verticalStepSize () const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Protected Member Functions

bool eventFilter (QObject *watched, QEvent *event) override
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

Handles scrolling for a Flickable and 2 attached ScrollBars.

WheelHandler filters events from a Flickable, a vertical ScrollBar and a horizontal ScrollBar. Wheel and KeyPress events (when keyNavigationEnabled is true) are used to scroll the Flickable. When filterMouseEvents is true, WheelHandler blocks mouse button input from reaching the Flickable and sets the interactive property of the scrollbars to false when touch input is used.

Wheel event handling behavior:

  • Pixel delta is ignored unless angle delta is not available because pixel delta scrolling is too slow. Qt Widgets doesn't use pixel delta either, so the default scroll speed should be consistent with Qt Widgets.
  • When using angle delta, scroll using the step increments defined by verticalStepSize and horizontalStepSize.
  • When one of the keyboard modifiers in pageScrollModifiers is used, scroll by pages.
  • When using a device that doesn't use 120 angle delta unit increments such as a touchpad, the verticalStepSize, horizontalStepSize and page increments (if using page scrolling) will be multiplied by angle delta / 120 to keep scrolling smooth.
  • If scrolling has happened in the last 400ms, use an internal QQuickItem stacked over the Flickable's contentItem to catch wheel events and use those wheel events to scroll, if possible. This prevents controls inside the Flickable's contentItem that allow scrolling to change the value (e.g., Sliders, SpinBoxes) from conflicting with scrolling the page.

Common usage with a Flickable:

/* SPDX-FileCopyrightText: 2021 Noah Davis <[email protected]>
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
import QtQuick 2.15
import QtQuick.Controls 2.15 as QQC2
import org.kde.kirigami 2.20 as Kirigami
QQC2.ApplicationWindow {
id: root
width: flickable.implicitWidth
height: flickable.implicitHeight
Flickable {
id: flickable
anchors.fill: parent
implicitWidth: wheelHandler.horizontalStepSize * 10 + leftMargin + rightMargin
implicitHeight: wheelHandler.verticalStepSize * 10 + topMargin + bottomMargin
leftMargin: QQC2.ScrollBar.vertical.visible && QQC2.ScrollBar.vertical.mirrored ? QQC2.ScrollBar.vertical.width : 0
rightMargin: QQC2.ScrollBar.vertical.visible && !QQC2.ScrollBar.vertical.mirrored ? QQC2.ScrollBar.vertical.width : 0
bottomMargin: QQC2.ScrollBar.horizontal.visible ? QQC2.ScrollBar.horizontal.height : 0
contentWidth: contentItem.childrenRect.width
contentHeight: contentItem.childrenRect.height
Kirigami.WheelHandler {
id: wheelHandler
target: flickable
}
QQC2.ScrollBar.vertical: QQC2.ScrollBar {
parent: flickable.parent
height: flickable.height - flickable.topMargin - flickable.bottomMargin
x: mirrored ? 0 : flickable.width - width
y: flickable.topMargin
active: flickable.QQC2.ScrollBar.horizontal.active
stepSize: wheelHandler.verticalStepSize / flickable.contentHeight
}
QQC2.ScrollBar.horizontal: QQC2.ScrollBar {
parent: flickable.parent
width: flickable.width - flickable.leftMargin - flickable.rightMargin
x: flickable.leftMargin
y: flickable.height - height
active: flickable.QQC2.ScrollBar.vertical.active
stepSize: wheelHandler.horizontalStepSize / flickable.contentWidth
}
Grid { // Example content
columns: Math.sqrt(visibleChildren.length)
Repeater {
model: 1000
delegate: Rectangle {
implicitWidth: wheelHandler.horizontalStepSize
implicitHeight: wheelHandler.verticalStepSize
gradient: Gradient {
orientation: index % 2 ? Gradient.Vertical : Gradient.Horizontal
GradientStop { position: 0; color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1) }
GradientStop { position: 1; color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1) }
}
}
}
}
}
}

Common usage inside of a ScrollView template:

/* SPDX-FileCopyrightText: 2021 Noah Davis <[email protected]>
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
import QtQuick 2.15
import QtQuick.Templates 2.15 as T
import QtQuick.Controls 2.15 as QQC2
import org.kde.kirigami 2.20 as Kirigami
T.ScrollView {
id: control
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
contentWidth + leftPadding + rightPadding)
implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
contentHeight + topPadding + bottomPadding)
leftPadding: mirrored && T.ScrollBar.vertical.visible && !Kirigami.Settings.isMobile ? T.ScrollBar.vertical.width : 0
rightPadding: !mirrored && T.ScrollBar.vertical.visible && !Kirigami.Settings.isMobile ? T.ScrollBar.vertical.width : 0
bottomPadding: T.ScrollBar.horizontal.visible && !Kirigami.Settings.isMobile ? T.ScrollBar.horizontal.height : 0
data: [
Kirigami.WheelHandler {
id: wheelHandler
target: control.contentItem
}
]
T.ScrollBar.vertical: QQC2.ScrollBar {
parent: control
x: control.mirrored ? 0 : control.width - width
y: control.topPadding
height: control.availableHeight
active: control.T.ScrollBar.horizontal.active
stepSize: wheelHandler.verticalStepSize / control.contentHeight
}
T.ScrollBar.horizontal: QQC2.ScrollBar {
parent: control
x: control.leftPadding
y: control.height - height
width: control.availableWidth
active: control.T.ScrollBar.vertical.active
stepSize: wheelHandler.horizontalStepSize / control.contentWidth
}
}

Definition at line 167 of file wheelhandler.h.

Property Documentation

◆ blockTargetWheel

bool WheelHandler::blockTargetWheel

This property holds whether the WheelHandler blocks all wheel events from reaching the Flickable.

When this property is false, scrolling the Flickable with WheelHandler will only block an event from reaching the Flickable if the Flickable is actually scrolled by WheelHandler.

NOTE: Wheel events created by touchpad gestures with pixel deltas will always be accepted no matter what. This is because they will cause the Flickable to jump back to where scrolling started unless the events are always accepted before they reach the Flickable.

The default value is true.

Definition at line 258 of file wheelhandler.h.

◆ filterMouseEvents

bool WheelHandler::filterMouseEvents
readwrite

This property holds whether the WheelHandler filters mouse events like a Qt Quick Controls ScrollView would.

Touch events are allowed to flick the view and they make the scrollbars not interactive.

Mouse events are not allowed to flick the view and they make the scrollbars interactive.

Hover events on the scrollbars and wheel events on anything also make the scrollbars interactive when this property is set to true.

The default value is false.

Since
KDE Frameworks 5.89

Definition at line 227 of file wheelhandler.h.

◆ horizontalStepSize

qreal WheelHandler::horizontalStepSize
readwrite

This property holds the horizontal step size.

The default value is equivalent to 20 * Qt.styleHints.wheelScrollLines. This is consistent with the default increment for QScrollArea.

See also
verticalStepSize
Since
KDE Frameworks 5.89

Definition at line 200 of file wheelhandler.h.

◆ keyNavigationEnabled

bool WheelHandler::keyNavigationEnabled
readwrite

This property holds whether the WheelHandler handles keyboard scrolling.

  • Left arrow scrolls a step to the left.
  • Right arrow scrolls a step to the right.
  • Up arrow scrolls a step upwards.
  • Down arrow scrolls a step downwards.
  • PageUp scrolls to the previous page.
  • PageDown scrolls to the next page.
  • Home scrolls to the beginning.
  • End scrolls to the end.
  • When Alt is held, scroll horizontally when using PageUp, PageDown, Home or End.

The default value is false.

Since
KDE Frameworks 5.89

Definition at line 247 of file wheelhandler.h.

◆ pageScrollModifiers

Qt::KeyboardModifiers WheelHandler::pageScrollModifiers
readwrite

This property holds the keyboard modifiers that will be used to start page scrolling.

The default value is equivalent to Qt.ControlModifier | Qt.ShiftModifier. This matches QScrollBar, which uses QAbstractSlider behavior.

Since
KDE Frameworks 5.89

Definition at line 211 of file wheelhandler.h.

◆ scrollFlickableTarget

bool WheelHandler::scrollFlickableTarget

This property holds whether the WheelHandler can use wheel events to scroll the Flickable.

The default value is true.

Definition at line 265 of file wheelhandler.h.

◆ target

QQuickItem * WheelHandler::target
readwrite

This property holds the Qt Quick Flickable that the WheelHandler will control.

Definition at line 174 of file wheelhandler.h.

◆ verticalStepSize

qreal WheelHandler::verticalStepSize
readwrite

This property holds the vertical step size.

The default value is equivalent to 20 * Qt.styleHints.wheelScrollLines. This is consistent with the default increment for QScrollArea.

See also
horizontalStepSize
Since
KDE Frameworks 5.89

Definition at line 187 of file wheelhandler.h.

Member Function Documentation

◆ scrollDown()

bool WheelHandler::scrollDown ( qreal  stepSize = -1)

Scroll down one step.

If the stepSize parameter is less than 0, the verticalStepSize will be used.

returns true if the contentItem was moved.

Since
KDE Frameworks 5.89

Definition at line 495 of file wheelhandler.cpp.

◆ scrollLeft()

bool WheelHandler::scrollLeft ( qreal  stepSize = -1)

Scroll left one step.

If the stepSize parameter is less than 0, the horizontalStepSize will be used.

returns true if the contentItem was moved.

Since
KDE Frameworks 5.89

Definition at line 506 of file wheelhandler.cpp.

◆ scrollRight()

bool WheelHandler::scrollRight ( qreal  stepSize = -1)

Scroll right one step.

If the stepSize parameter is less than 0, the horizontalStepSize will be used.

returns true if the contentItem was moved.

Since
KDE Frameworks 5.89

Definition at line 517 of file wheelhandler.cpp.

◆ scrollUp()

bool WheelHandler::scrollUp ( qreal  stepSize = -1)

Scroll up one step.

If the stepSize parameter is less than 0, the verticalStepSize will be used.

returns true if the contentItem was moved.

Since
KDE Frameworks 5.89

Definition at line 484 of file wheelhandler.cpp.

◆ wheel

void WheelHandler::wheel ( KirigamiWheelEvent wheel)
signal

This signal is emitted when a wheel event reaches the event filter, just before scrolling is handled.

Accepting the wheel event in the onWheel signal handler prevents scrolling from happening.


The documentation for this class was generated from the following files:
bool keyNavigationEnabled
This property holds whether the WheelHandler handles keyboard scrolling.
Definition: wheelhandler.h:247
bool filterMouseEvents
This property holds whether the WheelHandler filters mouse events like a Qt Quick Controls ScrollView...
Definition: wheelhandler.h:227
QQuickItem target
This property holds the Qt Quick Flickable that the WheelHandler will control.
Definition: wheelhandler.h:174
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 6 2023 04:13:18 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.