CopperSpice API  1.9.1
QWheelEvent Class Reference

The QWheelEvent class contains parameters that describe a wheel event. More...

Inheritance diagram for QWheelEvent:
QInputEvent QEvent

Public Methods

 QWheelEvent (const QPointF &pos, const QPointF &globalPosition, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orientation=Qt::Vertical)
 
 QWheelEvent (const QPointF &pos, const QPointF &globalPosition, QPoint pixelDelta, QPoint angleDelta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
 
 QWheelEvent (const QPointF &pos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orientation=Qt::Vertical)
 
QPoint angleDelta () const
 
Qt::MouseButtons buttons () const
 
int delta () const
 
QPoint globalPos () const
 
const QPointFglobalPosF () const
 
int globalX () const
 
int globalY () const
 
Qt::Orientation orientation () const
 
Qt::ScrollPhase phase () const
 
QPoint pixelDelta () const
 
QPoint pos () const
 
const QPointFposF () const
 
Qt::MouseEventSource source () const
 
int x () const
 
int y () const
 
- Public Methods inherited from QInputEvent
Qt::KeyboardModifiers modifiers () const
 
void setModifiers (Qt::KeyboardModifiers modifiers)
 
void setTimestamp (ulong timestamp)
 
ulong timestamp () const
 
- Public Methods inherited from QEvent
 QEvent (const QEvent &other)
 
 QEvent (Type type)
 
virtual ~QEvent ()
 
void accept ()
 
void ignore ()
 
bool isAccepted () const
 
QEvent & operator= (const QEvent &other)
 
void setAccepted (bool accepted)
 
bool spontaneous () const
 
Type type () const
 

Friends

class QApplication
 

Additional Inherited Members

- Public Types inherited from QEvent
enum  Type
 
- Static Public Methods inherited from QEvent
static int registerEventType (int hint=-1)
 

Detailed Description

The QWheelEvent class contains parameters that describe a wheel event. Wheel events are sent to the widget under the mouse cursor, but if that widget does not handle the event they are sent to the focus widget. The rotation distance is provided by delta(). The methods pos() and globalPos() return the mouse cursor's location at the time of the event.

A wheel event contains a special accept flag that indicates whether the receiver wants the event. You should call ignore() if you do not handle the wheel event; this ensures that it will be sent to the parent widget.

The QWidget::setEnabled() method can be used to enable or disable mouse and keyboard events for a widget. The event handler QWidget::wheelEvent() receives wheel events.

See also
QMouseEvent, QWidget::grabMouse()

Constructor & Destructor Documentation

QWheelEvent::QWheelEvent ( const QPointF pos,
int  delta,
Qt::MouseButtons  buttons,
Qt::KeyboardModifiers  modifiers,
Qt::Orientation  orientation = Qt::Vertical 
)

Constructs a wheel event object.

The position pos is the location of the mouse cursor within the widget. This constructor does not provide a way to set the global position, it is initialized to the result of QCursor::pos(). Use one of the other constructors if you need to specify the global position explicitly.

The buttons describe the state of the mouse buttons at the time of the event. The value for the delta contains the rotation distance, modifiers holds the keyboard modifier flags at the time of the event, and orientation holds the wheel's orientation.

See also
buttons(), delta(), pos()
QWheelEvent::QWheelEvent ( const QPointF pos,
const QPointF globalPosition,
int  delta,
Qt::MouseButtons  buttons,
Qt::KeyboardModifiers  modifiers,
Qt::Orientation  orientation = Qt::Vertical 
)

Constructs a wheel event object.

The position pos provides the location of the mouse cursor within the widget. The position in global coordinates is specified by globalPosition. The value for delta contains the rotation distance, modifiers holds the keyboard modifier flags at the time of the event, and orientation holds the wheel's orientation.

See also
buttons(), delta(), globalPos(), pos()
QWheelEvent::QWheelEvent ( const QPointF pos,
const QPointF globalPosition,
QPoint  pixelDelta,
QPoint  angleDelta,
Qt::MouseButtons  buttons,
Qt::KeyboardModifiers  modifiers,
Qt::ScrollPhase  phase,
Qt::MouseEventSource  source = Qt::MouseEventNotSynthesized 
)

Constructs a wheel event object.

The position pos provides the location of the mouse cursor within the window. The position in global coordinates is specified by globalPosition. The value for pixelDelta contains the scrolling distance in pixels on screen while angleDelta contains the wheel rotation distance. The value of pixelDelta can be null. The mouse and keyboard states at the time of the event are specified by buttons and modifiers. The scrolling phase of the event is specified by phase.

If the wheel event comes from a physical mouse wheel, source is set to Qt::MouseEventNotSynthesized. If it comes from a gesture detected by the operating system, or from a non-mouse hardware device, such that pixelDelta is directly related to finger movement, source is set to Qt::MouseEventSynthesizedBySystem. If it comes from CopperSpice the source will be set to Qt::MouseEventSynthesizedByCS.

See also
posF(), globalPosF(), angleDelta(), pixelDelta(), phase()

Method Documentation

QPoint QWheelEvent::angleDelta ( ) const
inline

Returns the distance that the wheel is rotated, in eighths of a degree. A positive value indicates that the wheel was rotated forwards away from the user, a negative value indicates that the wheel was rotated backwards toward the user.

Most mouse types work in steps of 15 degrees, in which case the delta value is a multiple of 120 since 120 units * 1/8 = 15 degrees.

However, some mice have finer-resolution wheels and send delta values that are less than 120 units (less than 15 degrees). To support this possibility, you can either cumulatively add the delta values from events until the value of 120 is reached, then scroll the widget, or you can partially scroll the widget in response to each wheel event.

void MyWidget::wheelEvent(QWheelEvent *event) {
QPoint numPixels = event->pixelDelta();
QPoint numDegrees = event->angleDelta() / 8;
if (! numPixels.isNull()) {
scrollWithPixels(numPixels);
} else if (!numDegrees.isNull()) {
QPoint numSteps = numDegrees / 15;
scrollWithDegrees(numSteps);
}
event->accept();
}

On platforms which support scrolling phases the delta may be null when either of these conditions is true.

  • Scrolling is about to begin but the distance did not yet change (Qt::ScrollBegin)
  • Scrolling has ended and the distance did not change anymore (Qt::ScrollEnd)
See also
pixelDelta()
Qt::MouseButtons QWheelEvent::buttons ( ) const
inline

Returns the mouse state when the event occurred.

int QWheelEvent::delta ( ) const
inline

Returns the distance that the wheel is rotated in eighths of a degree. A positive value indicates that the wheel was rotated forwards away from the user, a negative value indicates that the wheel was rotated backwards toward the user.

Most mouse types work in steps of 15 degrees, in which case the delta value is a multiple of 120 since 120 units * 1/8 = 15 degrees.

Some mice have finer-resolution wheels and send delta values that are less than 120 units (less than 15 degrees). To support this possibility, you can either cumulatively add the delta values from events until the value of 120 is reached, then scroll the widget, or you can partially scroll the widget in response to each wheel event.

void MyWidget::wheelEvent(QWheelEvent *event) {
int numDegrees = event->delta() / 8;
int numSteps = numDegrees / 15;
if (event->orientation() == Qt::Horizontal) {
scrollHorizontally(numSteps);
} else {
scrollVertically(numSteps);
}
event->accept();
}
QPoint QWheelEvent::globalPos ( ) const
inline

Returns the global position of the mouse pointer at the time of the event. This is important on asynchronous window systems such as X11. Whenever widgets are moved around in response to mouse events, globalPos() can differ from the current cursor position returned by QCursor::pos().

See also
globalX(), globalY()
const QPointF & QWheelEvent::globalPosF ( ) const
inline

Returns the global position of the mouse pointer at the time of the event. This is important on asynchronous window systems such as X11. Whenever widgets are moved around in response to mouse events, globalPosF() can differ from the current cursor position returned by QCursor::pos().

See also
posF()
int QWheelEvent::globalX ( ) const
inline

Returns the global x position of the mouse cursor at the time of the event.

See also
globalPos(), globalY()
int QWheelEvent::globalY ( ) const
inline

Returns the global y position of the mouse cursor at the time of the event.

See also
globalPos(), globalX()
Qt::Orientation QWheelEvent::orientation ( ) const
inline

Returns the current QWheelEvent orientation which will be either Qt::Vertical or Qt::Horizontal.

Qt::ScrollPhase QWheelEvent::phase ( ) const
inline

Returns the scrolling phase of this wheel event. The Qt::ScrollBegin and Qt::ScrollEnd phases are currently supported only on Mac OS X.

QPoint QWheelEvent::pixelDelta ( ) const
inline

Returns the scrolling distance in pixels on screen. This value is provided on platforms that support high-resolution pixel-based delta values such as Mac OS X. The value should be used directly to scroll content on screen.

void MyWidget::wheelEvent(QWheelEvent *event) {
QPoint numPixels = event->pixelDelta();
QPoint numDegrees = event->angleDelta() / 8;
if (! numPixels.isNull()) {
scrollWithPixels(numPixels);
} else if (!numDegrees.isNull()) {
QPoint numSteps = numDegrees / 15;
scrollWithDegrees(numSteps);
}
event->accept();
}

On platforms which support scrolling phases the delta may be null when either of these conditions is true.

  • Scrolling is about to begin but the distance did not yet change (Qt::ScrollBegin)
  • Scrolling has ended and the distance did not change anymore (Qt::ScrollEnd)

On X11 this value is driver specific and unreliable, use angleDelta() instead.

See also
angleDelta()
QPoint QWheelEvent::pos ( ) const
inline

Returns the position of the mouse cursor relative to the widget that received the event. If widgets are moved around in response to mouse events, use globalPos() instead of this method.

See also
globalPos(), x(), y()
const QPointF & QWheelEvent::posF ( ) const
inline

Returns the position of the mouse cursor relative to the widget that received the event. If widgets are moved around in response to mouse events, use globalPosF() instead of this method.

See also
globalPosF()
Qt::MouseEventSource QWheelEvent::source ( ) const
inline

Returns information about the wheel event source. The source can be used to distinguish between events that come from a mouse with a physical wheel and events that are generated by some other means, such as a flick gesture on a touch pad.

Many platforms provide no such information. On such platforms Qt::MouseEventNotSynthesized is returned always.

See also
Qt::MouseEventSource
int QWheelEvent::x ( ) const
inline

Returns the x position of the mouse cursor, relative to the widget that received the event.

See also
pos(), y()
int QWheelEvent::y ( ) const
inline

Returns the y position of the mouse cursor, relative to the widget that received the event.

See also
pos(), x()