QWheelEvent 類包含滾輪事件的描述參數。 更多...
| 頭: | #include <QWheelEvent> |
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Gui)
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 () return the mouse cursor's location at the time of the event.
滾輪事件包含指示接收者是否想要事件的,特殊接受標誌。應該調用 ignore () 若不處理滾輪事件;這確保它會被發送給父級 Widget。
The QWidget::setEnabled () 函數可用於啓用 (或禁用) 小部件的鼠標事件和鍵盤事件。
事件處理程序 QWidget::wheelEvent () 接收滾輪事件。
另請參閱 QMouseEvent and QWidget::grabMouse ().
構造滾輪事件對象。
The 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 .
另請參閱 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 ().
返迴隨事件交付的增量值是否反轉。
通常,垂直滾輪會産生 QWheelEvent 具有正增量值若滾輪頂部鏇轉離開操作它的手。同樣,水平滾輪運動會産生 QWheelEvent 具有正增量值若滾輪頂部嚮左移動。
不管怎樣,在某些平颱這是可配置的,因此如上述的相同操作會産生負增量值 (但幅度一樣)。利用反轉特性,滾輪事件消費者可以選擇始終跟隨滾輪方嚮,不管係統設置,但僅適用於特定 Widget (一種這樣的用例可能是用戶按如視覺 "Tumbler 轉盤" 鏇轉的相同方嚮鏇轉滾輪。另一用例是使滑動手柄跟隨觸摸闆上手指的移動方嚮,不管係統配置)。
注意: 很多平颱不提供這樣的信息。在這種平颱,inverted 始終返迴 false。
注意: Getter function for property inverted.
[override virtual]
bool
QWheelEvent::
isBeginEvent
() const
重實現: QSinglePointEvent::isBeginEvent() const .
返迴
true
if this event's
phase
() 是
Qt::ScrollBegin
.
[override virtual]
bool
QWheelEvent::
isEndEvent
() const
重實現: QSinglePointEvent::isEndEvent() const .
返迴
true
if this event's
phase
() 是
Qt::ScrollEnd
.
[override virtual]
bool
QWheelEvent::
isUpdateEvent
() const
重實現: QSinglePointEvent::isUpdateEvent() const .
返迴
true
if this event's
phase
() 是
Qt::ScrollUpdate
or
Qt::ScrollMomentum
.
返迴此滾輪事件的捲動階段。
注意: The Qt::ScrollBegin and Qt::ScrollEnd 階段目前僅 macOS 支持。
注意: Getter function for property phase.
返迴以屏幕像素為單位的捲動距離。此值由支持基於高分辨率像素的增量值的平颱 (譬如 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.