QMouseEvent 類

QMouseEvent 類包含鼠標事件的描述參數。 更多...

頭: #include <QMouseEvent>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
繼承: QSinglePointEvent

公共函數

QMouseEvent (QEvent::Type type , const QPointF & localPos , const QPointF & globalPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , const QPointingDevice * device = QPointingDevice::primaryPointingDevice())
QMouseEvent (QEvent::Type type , const QPointF & localPos , const QPointF & scenePos , const QPointF & globalPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , const QPointingDevice * device = QPointingDevice::primaryPointingDevice())
Qt::MouseEventFlags flags () const

詳細描述

齣現鼠標事件,當在 Widget 內按下 (或釋放) 鼠標按鈕 (或移動鼠標光標) 時。

纔發生鼠標移動事件,當按下鼠標按鈕時,除非有啓用鼠標追蹤采用 QWidget::setMouseTracking ().

Qt 自動抓取鼠標當在 Widget 內按下鼠標按鈕時;Widget 將繼續接收鼠標事件,直到最後釋放鼠標按鈕。

鼠標事件包含特殊接受標誌 (指示接收者是否想要事件)。應該調用 ignore () 若 Widget 不處理鼠標事件。鼠標事件會沿父級 Widget 鏈嚮上傳播,直到小部件接受它采用 accept (),或由事件過濾器消耗掉它。

注意: 若鼠標事件被傳播給 widget 其中 Qt::WA_NoMousePropagation 有設置,該鼠標事件將不會沿父級 Widget 鏈嚮上進一步傳播。

可以找到鍵盤修飾符鍵的狀態通過調用 modifiers () function, inherited from QInputEvent .

The position () function gives the cursor position relative to the widget or item that receives the mouse event. If you move the widget as a result of the mouse event, use the global position returned by globalPosition () 以避免晃動。

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

重實現 QWidget 事件處理程序, QWidget::mousePressEvent (), QWidget::mouseReleaseEvent (), QWidget::mouseDoubleClickEvent (),和 QWidget::mouseMoveEvent () 以在自己的 Widget 中接收鼠標事件。

另請參閱 QWidget::setMouseTracking (), QWidget::grabMouse (),和 QCursor::pos ().

成員函數文檔編製

QMouseEvent:: QMouseEvent ( QEvent::Type type , const QPointF & localPos , const QPointF & globalPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , const QPointingDevice * device = QPointingDevice::primaryPointingDevice())

Constructs a mouse event object originating from device .

The type 參數必須是 QEvent::MouseButtonPress , QEvent::MouseButtonRelease , QEvent::MouseButtonDblClick ,或 QEvent::MouseMove .

The localPos 是鼠標光標相對於接收 Widget 或項的位置。按屏幕坐標的光標位置的指定由 globalPos 。窗口位置會被設為相同值如 localPosbutton 導緻給定值事件來自 Qt::MouseButton 枚舉。若事件 type is MouseMove ,此事件的相應按鈕為 Qt::NoButton . buttons 是事件發生時所有按鈕的狀態, modifiers 是所有鍵盤修飾符的狀態。

QMouseEvent:: QMouseEvent ( QEvent::Type type , const QPointF & localPos , const QPointF & scenePos , const QPointF & globalPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , const QPointingDevice * device = QPointingDevice::primaryPointingDevice())

構造鼠標事件對象。

The type 參數必須是 QEvent::MouseButtonPress , QEvent::MouseButtonRelease , QEvent::MouseButtonDblClick ,或 QEvent::MouseMove .

localPos , scenePos and globalPos specify the mouse cursor's position relative to the receiving widget or item, window, and screen or desktop, respectively.

The button 導緻給定值事件來自 Qt::MouseButton 枚舉。若事件 type is MouseMove ,此事件的相應按鈕為 Qt::NoButton . buttons 是事件發生時所有按鈕的狀態, modifiers 是所有鍵盤修飾符的狀態。

Qt::MouseEventFlags QMouseEvent:: flags () const

返迴鼠標事件標誌。

鼠標事件標誌提供有關鼠標事件的額外信息。

另請參閱 Qt::MouseEventFlag and QGraphicsSceneMouseEvent::flags ().