QWheelEvent 類

QWheelEvent 類包含滾輪事件的描述參數。 更多...

頭: #include <QWheelEvent>
qmake: QT += gui
繼承: QInputEvent

公共函數

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

詳細描述

滾輪事件會被發送給鼠標光標下 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, source () 會返迴 Qt::MouseEventSynthesizedBySystem .

The functions pos() and globalPos() return the mouse cursor's location at the time of the event.

滾輪事件包含指示接收者是否想要事件的,特殊接受標誌。應該調用 ignore () 若不處理滾輪事件;這確保它會被發送給父級 Widget。

The QWidget::setEnabled () 函數可用於啓用 (或禁用) 小部件的鼠標事件和鍵盤事件。

事件處理程序 QWidget::wheelEvent () 接收滾輪事件。

另請參閱 QMouseEvent and QWidget::grabMouse ().

成員函數文檔編製

QWheelEvent:: QWheelEvent ( QPointF pos , QPointF globalPos , QPoint pixelDelta , QPoint angleDelta , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , Qt::ScrollPhase phase , bool inverted , Qt::MouseEventSource source = Qt::MouseEventNotSynthesized)

構造滾輪事件對象。

The pos 提供窗口中鼠標光標的位置。在全局坐標中位置的指定是通過 globalPos .

pixelDelta 包含以像素為單位的屏幕捲動距離,而 angleDelta contains the wheel rotation angle. pixelDelta 可選且可以是 null。

事件發生時的鼠標和鍵盤狀態的指定是通過 buttons and modifiers .

事件捲動階段的指定是通過 phase .

若滾輪事件來自物理鼠標滾輪, source 被設為 Qt::MouseEventNotSynthesized 。若它來自由操作係統檢測到的手勢,或來自非鼠標硬件設備,譬如 pixelDelta 與手指運動直接相關, source 被設為 Qt::MouseEventSynthesizedBySystem 。若它來自 Qt,source 被設為 Qt::MouseEventSynthesizedByQt .

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

該函數在 Qt 5.12 引入。

另請參閱 position (), globalPosition (), angleDelta (), pixelDelta (), phase (), inverted (),和 source ().

QPoint QWheelEvent:: angleDelta () const

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 當:

另請參閱 pixelDelta ().

Qt::MouseButtons QWheelEvent:: buttons () const

返迴事件齣現時的鼠標狀態。

QPointF QWheelEvent:: globalPosition () const

返迴鼠標指針的全局位置 當事件發生時 。這對異步窗口係統 (譬如 X11) 很重要;每當圍繞響應鼠標事件移動 Widget 時,globalposition() 會非常不同於當前光標位置返迴通過 QCursor::pos ().

另請參閱 position ().

bool QWheelEvent:: inverted () const

返迴隨事件交付的增量值是否反轉。

通常,垂直滾輪會産生 QWheelEvent 具有正增量值若滾輪頂部鏇轉離開操作它的手。同樣,水平滾輪運動會産生 QWheelEvent 具有正增量值若滾輪頂部嚮左移動。

不管怎樣,在某些平颱這是可配置的,因此如上述的相同操作會産生負增量值 (但幅度一樣)。利用反轉特性,滾輪事件消費者可以選擇始終跟隨滾輪方嚮,不管係統設置,但僅適用於特定 Widget (一種這樣的用例可能是用戶按如視覺 "Tumbler 轉盤" 鏇轉的相同方嚮鏇轉滾輪。另一用例是使滑動手柄跟隨觸摸闆上手指的移動方嚮,不管係統配置)。

注意: 很多平颱不提供這樣的信息。在這種平颱,inverted 始終返迴 false。

該函數在 Qt 5.7 引入。

Qt::ScrollPhase QWheelEvent:: phase () const

返迴此滾輪事件的捲動階段。

注意: The Qt::ScrollBegin and Qt::ScrollEnd 階段目前僅 macOS 支持。

該函數在 Qt 5.2 引入。

QPoint QWheelEvent:: pixelDelta () const

返迴以屏幕像素為單位的捲動距離。此值由支持基於高分辨率像素的增量值的平颱 (譬如 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 當:

注意: 在 X11,此值是驅動程序特定的且不可靠,使用 angleDelta () 代替

QPointF QWheelEvent:: position () const

返迴相對於接收事件 Widget 的鼠標光標位置。

若圍繞響應鼠標事件移動 Widget,使用 globalPosition () 而不是此函數。

該函數在 Qt 5.14 引入。

另請參閱 globalPosition ().

Qt::MouseEventSource QWheelEvent:: source () const

返迴滾輪事件源的有關信息。

源可以用於區分來自具有物理滾輪的鼠標事件,和由某些其它手段 (例如在觸摸闆上輕彈手勢) 生成的事件。

注意: 很多平颱不提供這種信息。在這種平颱 Qt::MouseEventNotSynthesized 始終被返迴。

該函數在 Qt 5.5 引入。

另請參閱 Qt::MouseEventSource .