QWheelEvent 类包含滚轮事件的描述参数。 更多...
头: | #include <QWheelEvent> |
CMake: |
find_package(Qt6 COMPONENTS Gui REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
继承: | QSinglePointEvent |
QWheelEvent (const QPointF & pos , const QPointF & globalPos , QPoint pixelDelta , QPoint angleDelta , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , Qt::ScrollPhase phase , bool inverted , Qt::MouseEventSource source = Qt::MouseEventNotSynthesized, const QPointingDevice * device = QPointingDevice::primaryPointingDevice()) | |
QPoint | angleDelta () const |
bool | inverted () const |
Qt::ScrollPhase | phase () const |
QPoint | pixelDelta () const |
virtual bool | isBeginEvent () const override |
virtual bool | isEndEvent () const override |
virtual bool | isUpdateEvent () const override |
滚轮事件会被发送给鼠标光标下 Widget,但若该小部件不处理事件,它们会被发送给聚焦小部件。鼠标滚轮和触摸板卷动手势都会生成滚轮事件。有 2 种方式能读取滚轮事件增量: angleDelta () returns the deltas in wheel degrees. These values are always provided. pixelDelta () returns the deltas in screen pixels, and is available on platforms that have high-resolution trackpads, such as macOS. If that is the case, device ()-> type () will return QInputDevice::DeviceType::Touchpad.
函数 position () 和 globalPosition () 返回事件出现时鼠标光标位置。
滚轮事件包含指示接收者是否想要事件的,特殊接受标志。应该调用 ignore () 若不处理滚轮事件;这确保它会被发送给父级 Widget。
QWidget::setEnabled () 函数可用于启用 (或禁用) 小部件的鼠标事件和键盘事件。
事件处理程序 QWidget::wheelEvent () 接收滚轮事件。
另请参阅 QMouseEvent and QWidget::grabMouse ().
[since 5.12]
QWheelEvent::
QWheelEvent
(const
QPointF
&
pos
, const
QPointF
&
globalPos
,
QPoint
pixelDelta
,
QPoint
angleDelta
,
Qt::MouseButtons
buttons
,
Qt::KeyboardModifiers
modifiers
,
Qt::ScrollPhase
phase
,
bool
inverted
,
Qt::MouseEventSource
source
= Qt::MouseEventNotSynthesized, const
QPointingDevice
*
device
= QPointingDevice::primaryPointingDevice())
构造滚轮事件对象。
pos 提供窗口中鼠标光标的位置。在全局坐标中位置的指定是通过 globalPos .
pixelDelta 包含以像素为单位的屏幕卷动距离,而 angleDelta contains the wheel rotation angle. pixelDelta 可选且可以是 null。
事件发生时的鼠标和键盘状态的指定是通过 buttons and modifiers .
事件卷动阶段的指定是通过 phase ,和 source indicates whether this is a genuine or artificial (synthesized) event.
If the system is configured to invert the delta values delivered with the event (such as natural scrolling of the touchpad on macOS),
inverted
应该为
true
。否则,
inverted
is
false
The device from which the wheel event originated is specified by device .
该函数在 Qt 5.12 引入。
另请参阅 position (), globalPosition (), angleDelta (), pixelDelta (), phase (), inverted (),和 device ().
Returns the relative amount that the wheel was 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.
angleDelta().y()
provides the angle through which the common vertical mouse wheel was rotated since the previous event.
angleDelta().x()
provides the angle through which the horizontal mouse wheel was rotated, if the mouse has a horizontal wheel; otherwise it stays at zero. Some mice allow the user to tilt the wheel to perform horizontal scrolling, and some touchpads support a horizontal scrolling gesture; that will also appear in
angleDelta().x()
.
大多数鼠标类型以 15 度步幅为单位工作,在这种情况下,增量值是 120 的倍增 (即:120 单位 *1/8 = 15 度)。
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. But to provide a more native feel, you should prefer pixelDelta () on platforms where it's available.
范例:
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(); }
注意: 当平台支持卷动 phases ,增量可能为 null 当:
注意: getter 函数对于特性 angleDelta。
另请参阅 pixelDelta ().
[since 5.7]
bool
QWheelEvent::
inverted
() const
返回随事件交付的增量值是否反转。
通常,垂直滚轮会产生 QWheelEvent 具有正增量值若滚轮顶部旋转离开操作它的手。同样,水平滚轮运动会产生 QWheelEvent 具有正增量值若滚轮顶部向左移动。
不管怎样,在某些平台这是可配置的,因此如上述的相同操作会产生负增量值 (但幅度一样)。利用反转特性,滚轮事件消费者可以选择始终跟随滚轮方向,不管系统设置,但仅适用于特定 Widget (一种这样的用例可能是用户按如视觉 "Tumbler 转盘" 旋转的相同方向旋转滚轮。另一用例是使滑动手柄跟随触摸板上手指的移动方向,不管系统配置)。
注意: 很多平台不提供这样的信息。在这种平台,inverted 始终返回 false。
注意: getter 函数对于特性 inverted。
该函数在 Qt 5.7 引入。
[override virtual]
bool
QWheelEvent::
isBeginEvent
() const
重实现: QSinglePointEvent::isBeginEvent () const.
返回
true
若此事件的
phase
() 是
Qt::ScrollBegin
.
[override virtual]
bool
QWheelEvent::
isEndEvent
() const
重实现: QSinglePointEvent::isEndEvent () const.
返回
true
若此事件的
phase
() 是
Qt::ScrollEnd
.
[override virtual]
bool
QWheelEvent::
isUpdateEvent
() const
重实现: QSinglePointEvent::isUpdateEvent () const.
返回
true
若此事件的
phase
() 是
Qt::ScrollUpdate
or
Qt::ScrollMomentum
.
[since 5.2]
Qt::ScrollPhase
QWheelEvent::
phase
() const
返回此滚轮事件的卷动阶段。
注意: Qt::ScrollBegin and Qt::ScrollEnd 阶段目前仅 macOS 支持。
注意: getter 函数对于特性 phase。
该函数在 Qt 5.2 引入。
返回以屏幕像素为单位的卷动距离。此值由支持基于高分辨率像素的增量值的平台 (譬如 macOS) 提供。应该将值直接用于卷动屏幕内容。
范例:
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(); }
注意: 当平台支持卷动 phases ,增量可能为 null 当:
注意: On X11 this value is driver-specific and unreliable, use angleDelta () 代替。
注意: Getter function for property pixelDelta.