QScroller¶
Synopsis¶
Functions¶
def
finalPosition
()def
handleInput
(input, position[, timestamp=0])def
pixelPerMeter
()def
scrollerProperties
()def
setSnapPositionsX
(first, interval)def
setSnapPositionsX
(positions)def
setSnapPositionsY
(first, interval)def
setSnapPositionsY
(positions)def
state
()def
stop
()def
target
()def
velocity
()
Slots¶
def
ensureVisible
(rect, xmargin, ymargin)def
ensureVisible
(rect, xmargin, ymargin, scrollTime)def
resendPrepareEvent
()def
scrollTo
(pos)def
scrollTo
(pos, scrollTime)def
setScrollerProperties
(prop)
Signals¶
def
scrollerPropertiesChanged
(arg__1)def
stateChanged
(newstate)
Static functions¶
def
activeScrollers
()def
grabGesture
(target[, gestureType=TouchGesture])def
grabbedGesture
(target)def
hasScroller
(target)def
scroller
(target)def
scroller
(target)def
ungrabGesture
(target)
Detailed Description¶
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 gestureQWidget *w = ...; QScroller::grabGesture(w, QScroller::LeftMouseButtonGesture);or directly like this:
QWidget *w = ...; QScroller *scroller = QScroller::scroller(w); scroller->scrollTo(QPointF(100, 100));The scrolled QObjects receive a
QScrollPrepareEvent
whenever the scroller needs to update its geometry information and aQScrollEvent
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 withFrameRate
on a per-QScroller
basis.The Dir View Example shows one way to use a
QScroller
with aQTreeView
. An example in thescroller
examples directory also demonstratesQScroller
.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 theplot
example in thescroller
examples directory.See also
QScrollEvent
QScrollPrepareEvent
QScrollerProperties
- class PySide2.QtWidgets.QScroller¶
- PySide2.QtWidgets.QScroller.State¶
This enum contains the different
QScroller
states.Constant
Description
QScroller.Inactive
The scroller is not scrolling and nothing is pressed.
QScroller.Pressed
A touch event was received or the mouse button was pressed but the scroll area is currently not dragged.
QScroller.Dragging
The scroll area is currently following the touch point or mouse.
QScroller.Scrolling
The scroll area is moving on it’s own.
- PySide2.QtWidgets.QScroller.ScrollerGestureType¶
This enum contains the different gesture types that are supported by the
QScroller
gesture recognizer.Constant
Description
QScroller.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.
QScroller.LeftMouseButtonGesture
The gesture recognizer will only trigger on left mouse button events.
QScroller.MiddleMouseButtonGesture
The gesture recognizer will only trigger on middle mouse button events.
QScroller.RightMouseButtonGesture
The gesture recognizer will only trigger on right mouse button events.
- PySide2.QtWidgets.QScroller.Input¶
This enum contains an input device agnostic view of input events that are relevant for
QScroller
.Constant
Description
QScroller.InputPress
The user pressed the input device (e.g.
MouseButtonPress
,GraphicsSceneMousePress
,TouchBegin
)QScroller.InputMove
The user moved the input device (e.g.
MouseMove
,GraphicsSceneMouseMove
,TouchUpdate
)QScroller.InputRelease
The user released the input device (e.g.
MouseButtonRelease
,GraphicsSceneMouseRelease
,TouchEnd
)
- static PySide2.QtWidgets.QScroller.activeScrollers()¶
- Return type:
Returns an application wide list of currently active
QScroller
objects. ActiveQScroller
objects are in astate()
that is notInactive
. This function is useful when writing your own gesture recognizer.
- PySide2.QtWidgets.QScroller.ensureVisible(rect, xmargin, ymargin)¶
- Parameters:
rect –
PySide2.QtCore.QRectF
xmargin – float
ymargin – float
Starts scrolling so that the rectangle
rect
is visible inside the viewport with additional margins specified in pixels byxmargin
andymargin
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()
.See also
- PySide2.QtWidgets.QScroller.ensureVisible(rect, xmargin, ymargin, scrollTime)
- Parameters:
rect –
PySide2.QtCore.QRectF
xmargin – float
ymargin – float
scrollTime – int
This is an overloaded function.
This version will reach its destination position in
scrollTime
milliseconds.
- PySide2.QtWidgets.QScroller.finalPosition()¶
- Return type:
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.
See also
- static PySide2.QtWidgets.QScroller.grabGesture(target[, gestureType=TouchGesture])¶
- Parameters:
target –
PySide2.QtCore.QObject
gestureType –
ScrollerGestureType
- Return type:
Registers a custom scroll gesture recognizer, grabs it for the
target
and returns the resulting gesture type. IfscrollGestureType
is set toTouchGesture
the gesture triggers on touch events. If it is set to one ofLeftMouseButtonGesture
,RightMouseButtonGesture
orMiddleMouseButtonGesture
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.
Note
To avoid unwanted side-effects, mouse events are consumed while the gesture is triggered. Since the initial mouse press event is not consumed, the gesture sends a fake mouse release event at the global position
(INT_MIN, INT_MIN)
. This ensures that internal states of the widget that received the original mouse press are consistent.See also
- static PySide2.QtWidgets.QScroller.grabbedGesture(target)¶
- Parameters:
target –
PySide2.QtCore.QObject
- Return type:
Returns the gesture type currently grabbed for the
target
or 0 if no gesture is grabbed.See also
- PySide2.QtWidgets.QScroller.handleInput(input, position[, timestamp=0])¶
- Parameters:
input –
Input
position –
PySide2.QtCore.QPointF
timestamp – int
- Return type:
bool
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 theinput
type, aposition
and a milli-secondtimestamp
. Theposition
needs to be in the target’s coordinate system.The return value is
true
if the event should be consumed by the calling filter orfalse
if the event should be forwarded to the control.Note
Using
grabGesture()
should be sufficient for most use cases.
- static PySide2.QtWidgets.QScroller.hasScroller(target)¶
- Parameters:
target –
PySide2.QtCore.QObject
- Return type:
bool
Returns
true
if aQScroller
object was already created fortarget
;false
otherwise.See also
- PySide2.QtWidgets.QScroller.pixelPerMeter()¶
- Return type:
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
.Note
Please note that this value should be physically correct. The actual DPI settings that Qt returns for the display may be reported wrongly on purpose by the underlying windowing system, for example on macOS.
- PySide2.QtWidgets.QScroller.resendPrepareEvent()¶
This function resends the
QScrollPrepareEvent
. Calling triggers aQScrollPrepareEvent
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.
- PySide2.QtWidgets.QScroller.scrollTo(pos)¶
- Parameters:
pos –
PySide2.QtCore.QPointF
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.See also
- PySide2.QtWidgets.QScroller.scrollTo(pos, scrollTime)
- Parameters:
pos –
PySide2.QtCore.QPointF
scrollTime – int
This is an overloaded function.
This version will reach its destination position in
scrollTime
milliseconds.
- static PySide2.QtWidgets.QScroller.scroller(target)¶
- Parameters:
target –
PySide2.QtCore.QObject
- Return type:
Returns the scroller for the given
target
. As long as the object exists this function will always return the sameQScroller
instance. If noQScroller
exists for thetarget
, one will implicitly be created. At no point more than oneQScroller
will be active on an object.See also
- static PySide2.QtWidgets.QScroller.scroller(target)
- Parameters:
target –
PySide2.QtCore.QObject
- Return type:
This is an overloaded function.
This is the const version of
scroller()
.
- PySide2.QtWidgets.QScroller.scrollerProperties()¶
- Return type:
This property holds The scroller properties of this scroller. The properties are used by the
QScroller
to determine its scrolling behavior..
- PySide2.QtWidgets.QScroller.scrollerPropertiesChanged(arg__1)¶
- Parameters:
- PySide2.QtWidgets.QScroller.setScrollerProperties(prop)¶
- Parameters:
This property holds The scroller properties of this scroller. The properties are used by the
QScroller
to determine its scrolling behavior..
- PySide2.QtWidgets.QScroller.setSnapPositionsX(positions)¶
- Parameters:
positions –
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.
- PySide2.QtWidgets.QScroller.setSnapPositionsX(first, interval)
- Parameters:
first – float
interval – float
Set the snap positions for the horizontal axis to regular spaced intervals. The first snap position is at
first
. The next atfirst
+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
- PySide2.QtWidgets.QScroller.setSnapPositionsY(positions)¶
- Parameters:
positions –
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.
- PySide2.QtWidgets.QScroller.setSnapPositionsY(first, interval)
- Parameters:
first – float
interval – float
Set the snap positions for the vertical axis to regular spaced intervals. The first snap position is at
first
. The next atfirst
+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
- PySide2.QtWidgets.QScroller.state()¶
- Return type:
This property holds the state of the scroller.
See also
State
- PySide2.QtWidgets.QScroller.stop()¶
Stops the scroller and resets its state back to Inactive.
- PySide2.QtWidgets.QScroller.target()¶
- Return type:
Returns the target object of this scroller.
See also
- static PySide2.QtWidgets.QScroller.ungrabGesture(target)¶
- Parameters:
target –
PySide2.QtCore.QObject
Ungrabs the gesture for the
target
. Does nothing if no gesture is grabbed.See also
- PySide2.QtWidgets.QScroller.velocity()¶
- Return type:
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
.See also
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.