Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QScroller Class

The QScroller class enables kinetic scrolling for any scrolling widget or graphics item. More...

 #include <QScroller>

Inherits: QObject.

This class was introduced in Qt 4.8.

Public Types

enum Input { InputPress, InputMove, InputRelease }
enum ScrollerGestureType { TouchGesture, LeftMouseButtonGesture, MiddleMouseButtonGesture, RightMouseButtonGesture }
enum State { Inactive, Pressed, Dragging, Scrolling }

Properties

  • 1 property inherited from QObject

Public Functions

QPointF finalPosition() const
bool handleInput(Input input, const QPointF & position, qint64 timestamp = 0)
QPointF pixelPerMeter() const
QScrollerProperties scrollerProperties() const
void setSnapPositionsX(const QList<qreal> & positions)
void setSnapPositionsX(qreal first, qreal interval)
void setSnapPositionsY(const QList<qreal> & positions)
void setSnapPositionsY(qreal first, qreal interval)
State state() const
void stop()
QObject * target() const
QPointF velocity() const
  • 31 public functions inherited from QObject

Public Slots

void ensureVisible(const QRectF & rect, qreal xmargin, qreal ymargin)
void ensureVisible(const QRectF & rect, qreal xmargin, qreal ymargin, int scrollTime)
void resendPrepareEvent()
void scrollTo(const QPointF & pos)
void scrollTo(const QPointF & pos, int scrollTime)
void setScrollerProperties(const QScrollerProperties & prop)
  • 1 public slot inherited from QObject

Signals

void scrollerPropertiesChanged(const QScrollerProperties & newProperties)
void stateChanged(QScroller::State newState)

Static Public Members

QList<QScroller *> activeScrollers()
Qt::GestureType grabGesture(QObject * target, ScrollerGestureType scrollGestureType = TouchGesture)
Qt::GestureType grabbedGesture(QObject * target)
bool hasScroller(QObject * target)
QScroller * scroller(QObject * target)
const QScroller * scroller(const QObject * target)
void ungrabGesture(QObject * target)
  • 11 static public members inherited from QObject

Additional Inherited Members

  • 9 protected functions inherited from QObject

Detailed Description

The QScroller class enables kinetic scrolling for any scrolling widget or graphics item.

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

 QWidget *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 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.

Several examples in the scroller examples directory show how QScroller, QScrollEvent and the scroller gesture can be used.

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.

See also QScrollEvent, QScrollPrepareEvent, and QScrollerProperties.

Member Type Documentation

enum QScroller::Input

This enum contains an input device agnostic view of input events that are relevant for QScroller.

ConstantValueDescription
QScroller::InputPress1The user pressed the input device (e.g. QEvent::MouseButtonPress, QEvent::GraphicsSceneMousePress, QEvent::TouchBegin)
QScroller::InputMove2The user moved the input device (e.g. QEvent::MouseMove, QEvent::GraphicsSceneMouseMove, QEvent::TouchUpdate)
QScroller::InputRelease3The user released the input device (e.g. QEvent::MouseButtonRelease, QEvent::GraphicsSceneMouseRelease, QEvent::TouchEnd)

enum QScroller::ScrollerGestureType

This enum contains the different gesture types that are supported by the QScroller gesture recognizer.

ConstantValueDescription
QScroller::TouchGesture0The 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::LeftMouseButtonGesture1The gesture recognizer will only trigger on left mouse button events.
QScroller::MiddleMouseButtonGesture3The gesture recognizer will only trigger on middle mouse button events.
QScroller::RightMouseButtonGesture2The gesture recognizer will only trigger on right mouse button events.

enum QScroller::State

This enum contains the different QScroller states.

ConstantValueDescription
QScroller::Inactive0The scroller is not scrolling and nothing is pressed.
QScroller::Pressed1A touch event was received or the mouse button was pressed but the scroll area is currently not dragged.
QScroller::Dragging2The scroll area is currently following the touch point or mouse.
QScroller::Scrolling3The scroll area is moving on it's own.

Property Documentation

scrollerProperties : QScrollerProperties

This property holds the scroller properties of this scroller. The properties are used by the QScroller to determine its scrolling behavior.

Access functions:

QScrollerProperties scrollerProperties() const
void setScrollerProperties(const QScrollerProperties & prop)

Notifier signal:

void scrollerPropertiesChanged(const QScrollerProperties & newProperties)

state : const State

This property holds the state of the scroller.

Access functions:

State state() const

Notifier signal:

void stateChanged(QScroller::State newState)

See also QScroller::State.

Member Function Documentation

QList<QScroller *> QScroller::activeScrollers() [static]

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.

void QScroller::ensureVisible(const QRectF & rect, qreal xmargin, qreal ymargin) [slot]

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().

See also scrollTo().

void QScroller::ensureVisible(const QRectF & rect, qreal xmargin, qreal ymargin, int scrollTime) [slot]

This is an overloaded function.

This version will reach its destination position in scrollTime milliseconds.

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.

See also pixelPerMeter() and scrollTo().

Qt::GestureType QScroller::grabGesture(QObject * target, ScrollerGestureType scrollGestureType = TouchGesture) [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.

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 ungrabGesture() and grabbedGesture().

Qt::GestureType QScroller::grabbedGesture(QObject * target) [static]

Returns the gesture type currently grabbed for the target or 0 if no gesture is grabbed.

See also grabGesture() and ungrabGesture().

bool QScroller::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. 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.

Note: Using grabGesture() should be sufficient for most use cases.

bool QScroller::hasScroller(QObject * target) [static]

Returns true if a QScroller object was already created for target; false otherwise.

See also scroller().

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.

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 Mac OS X.

void QScroller::resendPrepareEvent() [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.

void QScroller::scrollTo(const QPointF & pos) [slot]

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 ensureVisible().

void QScroller::scrollTo(const QPointF & pos, int scrollTime) [slot]

This is an overloaded function.

This version will reach its destination position in scrollTime milliseconds.

QScroller * QScroller::scroller(QObject * target) [static]

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.

See also hasScroller() and target().

const QScroller * QScroller::scroller(const QObject * target) [static]

This is an overloaded function.

This is the const version of scroller().

void QScroller::setSnapPositionsX(const QList<qreal> & 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.

void QScroller::setSnapPositionsX(qreal first, qreal interval)

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

void QScroller::setSnapPositionsY(const QList<qreal> & 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.

void QScroller::setSnapPositionsY(qreal first, qreal interval)

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

void QScroller::stop()

Stops the scroller and resets its state back to Inactive.

QObject * QScroller::target() const

Returns the target object of this scroller.

See also hasScroller() and scroller().

void QScroller::ungrabGesture(QObject * target) [static]

Ungrabs the gesture for the target. Does nothing if no gesture is grabbed.

See also grabGesture() and grabbedGesture().

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.

See also pixelPerMeter().

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web