![]() |
Qt 6.x
The Qt SDK
|
The QScroller class enables kinetic scrolling for any scrolling widget or graphics item. More...
#include <qscroller.h>
Public Types | |
enum | State { Inactive , Pressed , Dragging , Scrolling } |
This enum contains the different QScroller states. More... | |
enum | ScrollerGestureType { TouchGesture , LeftMouseButtonGesture , RightMouseButtonGesture , MiddleMouseButtonGesture } |
This enum contains the different gesture types that are supported by the QScroller gesture recognizer. More... | |
enum | Input { InputPress = 1 , InputMove , InputRelease } |
This enum contains an input device agnostic view of input events that are relevant for QScroller. More... | |
Public Slots | |
void | setScrollerProperties (const QScrollerProperties &prop) |
void | scrollTo (const QPointF &pos) |
Starts scrolling the widget so that point pos is at the top-left position in the viewport. | |
void | scrollTo (const QPointF &pos, int scrollTime) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version will reach its destination position in scrollTime milliseconds. | |
void | ensureVisible (const QRectF &rect, qreal xmargin, qreal ymargin) |
Starts scrolling so that the rectangle rect is visible inside the viewport with additional margins specified in pixels by xmargin and ymargin around the rect. | |
void | ensureVisible (const QRectF &rect, qreal xmargin, qreal ymargin, int scrollTime) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version will reach its destination position in scrollTime milliseconds. | |
void | resendPrepareEvent () |
This function resends the QScrollPrepareEvent. | |
![]() | |
void | deleteLater () |
\threadsafe | |
Signals | |
void | stateChanged (QScroller::State newstate) |
QScroller emits this signal whenever the state changes. | |
void | scrollerPropertiesChanged (const QScrollerProperties &) |
QScroller emits this signal whenever its scroller properties change. | |
![]() | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
Public Member Functions | |
QObject * | target () const |
Returns the target object of this scroller. | |
State | state () const |
bool | handleInput (Input input, const QPointF &position, qint64 timestamp=0) |
This function is used by gesture recognizers to inform the scroller about a new input event. | |
void | stop () |
Stops the scroller and resets its state back to Inactive. | |
QPointF | velocity () const |
Returns the current scrolling velocity in meter per second when the state is Scrolling or Dragging. | |
QPointF | finalPosition () const |
Returns the estimated final position for the current scroll movement. | |
QPointF | pixelPerMeter () const |
Returns the pixel per meter metric for the scrolled widget. | |
QScrollerProperties | scrollerProperties () const |
void | setSnapPositionsX (const QList< qreal > &positions) |
Set the snap positions for the horizontal axis to a list of positions. | |
void | setSnapPositionsX (qreal first, qreal interval) |
Set the snap positions for the horizontal axis to regular spaced intervals. | |
void | setSnapPositionsY (const QList< qreal > &positions) |
Set the snap positions for the vertical axis to a list of positions. | |
void | setSnapPositionsY (qreal first, qreal interval) |
Set the snap positions for the vertical axis to regular spaced intervals. | |
![]() | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Static Public Member Functions | |
static bool | hasScroller (QObject *target) |
Returns true if a QScroller object was already created for target; false otherwise. | |
static QScroller * | scroller (QObject *target) |
Returns the scroller for the given target. | |
static const QScroller * | scroller (const QObject *target) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This is the const version of scroller(). | |
static Qt::GestureType | grabGesture (QObject *target, ScrollerGestureType gestureType=TouchGesture) |
Registers a custom scroll gesture recognizer, grabs it for the target and returns the resulting gesture type. | |
static Qt::GestureType | grabbedGesture (QObject *target) |
Returns the gesture type currently grabbed for the target or 0 if no gesture is grabbed. | |
static void | ungrabGesture (QObject *target) |
Ungrabs the gesture for the target. | |
static QList< QScroller * > | activeScrollers () |
Returns an application wide list of currently active QScroller objects. | |
![]() | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
Properties | |
State | state |
the state of the scroller | |
QScrollerProperties | scrollerProperties |
The scroller properties of this scroller. | |
![]() | |
QString | objectName |
the name of this object | |
Private Member Functions | |
virtual | ~QScroller () |
Friends | |
class | QFlickGestureRecognizer |
Additional Inherited Members | |
![]() | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
![]() | |
QScopedPointer< QObjectData > | d_ptr |
![]() | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
The QScroller class enables kinetic scrolling for any scrolling widget or graphics item.
\inmodule QtWidgets
With kinetic scrolling, the user can push the widget in a given direction and it will continue to scroll in this direction until it is stopped either by the user or by friction. Aspects of inertia, friction and other physical concepts can be changed in order to fine-tune an intuitive user experience.
The QScroller object is the object that stores the current position and scrolling speed and takes care of updates. QScroller can be triggered by a flick gesture
or directly like this:
The scrolled QObjects receive a QScrollPrepareEvent whenever the scroller needs to update its geometry information and a QScrollEvent whenever the content of the object should actually be scrolled.
The scroller uses the global QAbstractAnimation timer to generate its QScrollEvents. This can be changed with QScrollerProperties::FrameRate on a per-QScroller basis.
Even though this kinetic scroller has a large number of settings available via QScrollerProperties, we recommend that you leave them all at their default, platform optimized values. Before changing them you can experiment with the plot
example in the scroller
examples directory.
Definition at line 25 of file qscroller.h.
enum QScroller::Input |
This enum contains an input device agnostic view of input events that are relevant for QScroller.
\value InputPress The user pressed the input device (e.g. QEvent::MouseButtonPress, QEvent::GraphicsSceneMousePress, QEvent::TouchBegin)
\value InputMove The user moved the input device (e.g. QEvent::MouseMove, QEvent::GraphicsSceneMouseMove, QEvent::TouchUpdate)
\value InputRelease The user released the input device (e.g. QEvent::MouseButtonRelease, QEvent::GraphicsSceneMouseRelease, QEvent::TouchEnd)
Enumerator | |
---|---|
InputPress | |
InputMove | |
InputRelease |
Definition at line 50 of file qscroller.h.
This enum contains the different gesture types that are supported by the QScroller gesture recognizer.
\value TouchGesture The gesture recognizer will only trigger on touch events. Specifically it will react on single touch points when using a touch screen and dual touch points when using a touchpad. \value LeftMouseButtonGesture The gesture recognizer will only trigger on left mouse button events. \value MiddleMouseButtonGesture The gesture recognizer will only trigger on middle mouse button events. \value RightMouseButtonGesture The gesture recognizer will only trigger on right mouse button events.
Enumerator | |
---|---|
TouchGesture | |
LeftMouseButtonGesture | |
RightMouseButtonGesture | |
MiddleMouseButtonGesture |
Definition at line 42 of file qscroller.h.
enum QScroller::State |
This enum contains the different QScroller states.
\value Inactive The scroller is not scrolling and nothing is pressed. \value Pressed A touch event was received or the mouse button was pressed but the scroll area is currently not dragged. \value Dragging The scroll area is currently following the touch point or mouse. \value Scrolling The scroll area is moving on it's own.
Enumerator | |
---|---|
Inactive | |
Pressed | |
Dragging | |
Scrolling |
Definition at line 33 of file qscroller.h.
|
privatevirtual |
Definition at line 455 of file qscroller.cpp.
References d, and QGestureRecognizer::unregisterRecognizer().
Returns an application wide list of currently active QScroller objects.
Active QScroller objects are in a state() that is not QScroller::Inactive. This function is useful when writing your own gesture recognizer.
Definition at line 284 of file qscroller.cpp.
Referenced by QFlickGestureRecognizer::recognize().
Starts scrolling so that the rectangle rect is visible inside the viewport with additional margins specified in pixels by xmargin and ymargin around the rect.
In cases where it is not possible to fit the rect plus margins inside the viewport the contents are scrolled so that as much as possible is visible from rect.
The scrolling speed is calculated so that the given position is reached after a platform-defined time span.
This function performs the actual scrolling by calling scrollTo().
Definition at line 686 of file qscroller.cpp.
References ensureVisible(), and rect.
Referenced by ensureVisible().
|
slot |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version will reach its destination position in scrollTime milliseconds.
Definition at line 696 of file qscroller.cpp.
References QRectF::bottom(), clampToRect(), QRectF::contains(), d, Dragging, QRectF::height(), QSizeF::height(), Qt::Horizontal, Inactive, QRectF::left(), Pressed, qCDebug, rect, QRectF::right(), scrollTo(), QPointF::setX(), QPointF::setY(), QRectF::top(), Qt::Vertical, QRectF::width(), and QSizeF::width().
QPointF QScroller::finalPosition | ( | ) | const |
Returns the estimated final position for the current scroll movement.
Returns the current position if the scroller state is not Scrolling. The result is undefined when the scroller state is Inactive.
The target position is in pixel.
Definition at line 601 of file qscroller.cpp.
References d, Qt::Horizontal, and Qt::Vertical.
|
static |
Returns the gesture type currently grabbed for the target or 0 if no gesture is grabbed.
Definition at line 399 of file qscroller.cpp.
References scroller.
|
static |
Registers a custom scroll gesture recognizer, grabs it for the target and returns the resulting gesture type.
If scrollGestureType is set to TouchGesture the gesture triggers on touch events. If it is set to one of LeftMouseButtonGesture, RightMouseButtonGesture or MiddleMouseButtonGesture it triggers on mouse events of the corresponding button.
Only one scroll gesture can be active on a single object at the same time. If you call this function twice on the same object, it will ungrab the existing gesture before grabbing the new one.
{(INT_MIN, INT_MIN)}. This ensures that internal states of the widget that received the original mouse press are consistent.Definition at line 355 of file qscroller.cpp.
References button, QWidget::grabGesture(), Qt::LeftButton, LeftMouseButtonGesture, Qt::MiddleButton, MiddleMouseButtonGesture, Qt::NoButton, QFlickGestureRecognizer, QGestureRecognizer::registerRecognizer(), Qt::RightButton, RightMouseButtonGesture, scroller, QWidget::setAttribute(), sp, target(), TouchGesture, ungrabGesture(), Qt::WA_AcceptTouchEvents, and widget.
Referenced by QPixmapStyle::polish().
This function is used by gesture recognizers to inform the scroller about a new input event.
The scroller changes its internal state() according to the input event and its attached scroller properties. The scroller doesn't distinguish between the kind of input device the event came from. Therefore the event needs to be split into the input type, a position and a milli-second timestamp. The position needs to be in the target's coordinate system.
The return value is true
if the event should be consumed by the calling filter or false
if the event should be forwarded to the control.
Definition at line 942 of file qscroller.cpp.
References d, Dragging, i, Inactive, InputMove, InputPress, InputRelease, QScrollerPrivate::moveWhileDragging(), QScrollerPrivate::moveWhilePressed(), position(), Pressed, QScrollerPrivate::pressWhileInactive(), QScrollerPrivate::pressWhileScrolling(), qCDebug, QScrollerPrivate::releaseWhileDragging(), QScrollerPrivate::releaseWhilePressed(), Scrolling, and state.
Referenced by QFlickGestureRecognizer::recognize().
|
static |
Returns true
if a QScroller object was already created for target; false
otherwise.
Definition at line 242 of file qscroller.cpp.
Referenced by QFlickGesture::QFlickGesture().
QPointF QScroller::pixelPerMeter | ( | ) | const |
Returns the pixel per meter metric for the scrolled widget.
The value is reported for both the x and y axis separately by using a QPointF.
Definition at line 521 of file qscroller.cpp.
References d, QLineF::length(), QPointF::rx(), QPointF::ry(), scene, tr, and QGraphicsScene::views().
|
slot |
This function resends the QScrollPrepareEvent.
Calling resendPrepareEvent triggers a QScrollPrepareEvent from the scroller. This allows the receiver to re-set content position and content size while scrolling. Calling this function while in the Inactive state is useless as the prepare event is sent again before scrolling starts.
Definition at line 770 of file qscroller.cpp.
References d.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This is the const version of scroller().
Definition at line 274 of file qscroller.cpp.
References scroller.
Returns the scroller for the given target.
As long as the object exists this function will always return the same QScroller instance. If no QScroller exists for the target, one will implicitly be created. At no point more than one QScroller will be active on an object.
Definition at line 255 of file qscroller.cpp.
References contains(), and qWarning.
Referenced by QFlickGesture::QFlickGesture(), and QAbstractItemView::viewportEvent().
QScrollerProperties QScroller::scrollerProperties | ( | ) | const |
Definition at line 313 of file qscroller.cpp.
References d.
|
signal |
QScroller emits this signal whenever its scroller properties change.
newProperties are the new scroller properties.
Referenced by setScrollerProperties().
Starts scrolling the widget so that point pos is at the top-left position in the viewport.
The behaviour when scrolling outside the valid scroll area is undefined. In this case the scroller might or might not overshoot.
The scrolling speed will be calculated so that the given position will be reached after a platform-defined time span.
pos is given in viewport coordinates.
Definition at line 622 of file qscroller.cpp.
References pos, and scrollTo().
Referenced by ensureVisible(), and scrollTo().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version will reach its destination position in scrollTime milliseconds.
Definition at line 632 of file qscroller.cpp.
References clampToRect(), d, Dragging, Qt::Horizontal, Inactive, pos, Pressed, qCDebug, qIsNaN(), Scrolling, QScrollerPrivate::ScrollTypeScrollTo, QPointF::setX(), QPointF::setY(), time, velocity(), Qt::Vertical, QPointF::x(), and QPointF::y().
|
slot |
Definition at line 319 of file qscroller.cpp.
References d, emit, scrollerPropertiesChanged(), and sp.
Set the snap positions for the horizontal axis to a list of positions.
This overwrites all previously set snap positions and also a previously set snapping interval. Snapping can be deactivated by setting an empty list of positions.
Definition at line 781 of file qscroller.cpp.
Set the snap positions for the horizontal axis to regular spaced intervals.
The first snap position is at first. The next at first + interval. This can be used to implement a list header. This overwrites all previously set snap positions and also a previously set snapping interval. Snapping can be deactivated by setting an interval of 0.0
Definition at line 797 of file qscroller.cpp.
References d.
Set the snap positions for the vertical axis to a list of positions.
This overwrites all previously set snap positions and also a previously set snapping interval. Snapping can be deactivated by setting an empty list of positions.
Definition at line 812 of file qscroller.cpp.
Set the snap positions for the vertical axis to regular spaced intervals.
The first snap position is at first. The next at first + interval. This overwrites all previously set snap positions and also a previously set snapping interval. Snapping can be deactivated by setting an interval of 0.0
Definition at line 827 of file qscroller.cpp.
References d.
QScroller::State QScroller::state | ( | ) | const |
Definition at line 484 of file qscroller.cpp.
References d.
|
signal |
void QScroller::stop | ( | ) |
Stops the scroller and resets its state back to Inactive.
Definition at line 493 of file qscroller.cpp.
References clampToRect(), d, Qt::Horizontal, Inactive, qIsNaN(), QPointF::setX(), QPointF::setY(), Qt::Vertical, QPointF::x(), and QPointF::y().
Referenced by QFlickGestureRecognizer::recognize().
QObject * QScroller::target | ( | ) | const |
Returns the target object of this scroller.
Definition at line 293 of file qscroller.cpp.
References d.
Referenced by grabGesture(), and ungrabGesture().
Ungrabs the gesture for the target.
Does nothing if no gesture is grabbed.
Definition at line 414 of file qscroller.cpp.
References scroller, sp, target(), QWidget::ungrabGesture(), QGestureRecognizer::unregisterRecognizer(), and widget.
Referenced by grabGesture(), and QPixmapStyle::unpolish().
QPointF QScroller::velocity | ( | ) | const |
Returns the current scrolling velocity in meter per second when the state is Scrolling or Dragging.
Returns a zero velocity otherwise.
The velocity is reported for both the x and y axis separately by using a QPointF.
Definition at line 556 of file qscroller.cpp.
References d, differentialForProgress(), Dragging, now, qSign(), Scrolling, QPointF::setX(), QPointF::setY(), sp, and state.
Referenced by scrollTo().
|
friend |
Definition at line 110 of file qscroller.h.
Referenced by grabGesture().
|
readwrite |
The scroller properties of this scroller.
The properties are used by the QScroller to determine its scrolling behavior.
Definition at line 114 of file qscroller.h.
Referenced by QFlickGestureRecognizer::recognize().
|
read |
the state of the scroller
Definition at line 114 of file qscroller.h.
Referenced by QFlickGestureRecognizer::recognize(), and velocity().