QWheelEvent 类

The QWheelEvent 类包含滚轮事件的描述参数。 更多...

头: #include <QWheelEvent>
继承: QInputEvent

公共函数

QWheelEvent (const QPoint & pos , int delta , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , Qt::Orientation orient = Qt::Vertical)
QWheelEvent (const QPoint & pos , const QPoint & globalPos , int delta , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , Qt::Orientation orient = Qt::Vertical)
Qt::MouseButtons buttons () const
int delta () const
const QPoint & globalPos () const
int globalX () const
int globalY () const
Qt::Orientation orientation () const
const QPoint & pos () const
int x () const
int y () const

额外继承成员

详细描述

The QWheelEvent 类包含滚轮事件的描述参数。

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 ()。函数 pos () 和 globalPos () 返回事件出现时鼠标光标位置。

滚轮事件包含指示接收者是否想要事件的,特殊接受标志。应该调用 ignore () 若不处理滚轮事件;这确保它会被发送给父级 Widget。

The QWidget::setEnabled () 函数可用于启用 (或禁用) 小部件的鼠标事件和键盘事件。

事件处理程序 QWidget::wheelEvent () 接收滚轮事件。

另请参阅 QMouseEvent and QWidget::grabMouse ().

成员函数文档编制

QWheelEvent:: QWheelEvent (const QPoint & pos , int delta , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , Qt::Orientation orient = Qt::Vertical)

构造滚轮事件对象。

The position, pos , is the location of the mouse cursor within the widget. The globalPos () 被初始化为 QCursor::pos () which is usually, but not always, correct. Use the other constructor if you need to specify the global position explicitly.

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

另请参阅 pos (), delta (),和 state ().

QWheelEvent:: QWheelEvent (const QPoint & pos , const QPoint & globalPos , int delta , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , Qt::Orientation orient = Qt::Vertical)

构造滚轮事件对象。

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

另请参阅 pos (), globalPos (), delta (),和 state ().

Qt::MouseButtons QWheelEvent:: buttons () const

返回事件出现时的鼠标状态。

int QWheelEvent:: delta () const

返回旋转滚轮的距离,以八分之一度为单位。正值指示滚轮向前旋转远离用户;负值指示滚轮向后旋转朝着用户。

大多数鼠标类型以 15 度步幅为单位工作,在这种情况下,增量值是 120 的倍增 (即:120 单位 *1/8 = 15 度)。

不管怎样,一些鼠标拥有更精细分辨率的滚轮,并发送小于 120 单位 (小于 15 度) 的增量值。要支持这种可能性,可以累加来自事件的增量值,直到达到 120,然后卷动 Widget,或者,可以部分卷动小部件以响应各滚轮事件。

范例:

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();
}
					

const QPoint & QWheelEvent:: globalPos () const

返回鼠标指针的全局位置 当事件发生时 。这对异步窗口系统 (譬如 X11) 很重要。每当围绕响应鼠标事件移动 Widget 时,globalPos() 会非常不同于当前光标位置返回通过 QCursor::pos ().

另请参阅 globalX () 和 globalY ().

int QWheelEvent:: globalX () const

返回事件发生时的鼠标光标全局 X 位置。

另请参阅 globalY () 和 globalPos ().

int QWheelEvent:: globalY () const

返回事件发生时的鼠标光标全局 Y 位置。

另请参阅 globalX () 和 globalPos ().

Qt::Orientation QWheelEvent:: orientation () const

Returns the wheel's orientation.

const QPoint & QWheelEvent:: pos () const

返回相对于接收事件 Widget 的鼠标光标位置。

若围绕响应鼠标事件移动 Widget,使用 globalPos () 而不是此函数。

另请参阅 x (), y (),和 globalPos ().

int QWheelEvent:: x () const

返回相对于接收事件 Widget 的鼠标光标 X 位置。

另请参阅 y () 和 pos ().

int QWheelEvent:: y () const

返回相对于接收事件 Widget 的鼠标光标 Y 位置。

另请参阅 x () 和 pos ().