Obsolete Members for QMouseEvent
QMouseEvent 类的以下成员已被废弃。提供这些成员是为了确保旧源代码能够正常运行。我们强烈建议不要在新代码中使用它们。
公共函数
(deprecated in 6.4) | QMouseEvent(QEvent::Type type, const QPointF &localPos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, const QPointingDevice *device = QPointingDevice::primaryPointingDevice()) |
(deprecated in 6.0) QPoint | globalPos() const |
(deprecated in 6.0) int | globalX() const |
(deprecated in 6.0) int | globalY() const |
(deprecated in 6.0) QPointF | localPos() const |
(deprecated in 6.0) QPoint | pos() const |
(deprecated in 6.0) QPointF | screenPos() const |
(deprecated in 6.0) Qt::MouseEventSource | source() const |
(deprecated in 6.0) QPointF | windowPos() const |
(deprecated in 6.0) int | x() const |
(deprecated in 6.0) int | y() const |
成员函数文档
[deprecated in 6.4] QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF &localPos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, const QPointingDevice *device = QPointingDevice::primaryPointingDevice())
自 6.4 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。
请改用其他构造函数(必须指定全局位置)。
构建一个源自device 的鼠标事件对象。
type 参数必须是QEvent::MouseButtonPress 、QEvent::MouseButtonRelease 、QEvent::MouseButtonDblClick 或QEvent::MouseMove 中的一个。
localPos 表示鼠标光标相对于接收控件或项的位置。窗口位置被设置为与localPos 相同的值。触发该事件的button 被指定为Qt::MouseButton 枚举中的一个值。如果事件type 为MouseMove ,则该事件对应的按钮为Qt::NoButton 。事件发生时的鼠标和键盘状态由buttons 和modifiers 指定。
globalPosition() 被初始化为QCursor::pos(),这可能并不合适。请使用其他构造函数来显式指定全局位置。
[deprecated in 6.0] QPoint QMouseEvent::globalPos() const
自 6.0 版本起,此函数已被废弃。我们强烈建议不要在新的代码中使用它。
请改用 `globalPosition().toPoint()`。
返回事件发生时鼠标光标的全局位置。这在 X11 等异步窗口系统中尤为重要。每当您根据鼠标事件移动控件时,globalPos() 的返回值可能与当前指针位置QCursor::pos() 以及QWidget::mapToGlobal(pos()) 的返回值存在显著差异。
[deprecated in 6.0] int QMouseEvent::globalX() const
自 6.0 版本起,此函数已弃用。我们强烈建议不要在新代码中使用它。
请改用 `globalPosition()` 或 `x()`。
返回事件发生时鼠标光标在全球坐标系中的 x 坐标。
[deprecated in 6.0] int QMouseEvent::globalY() const
自 6.0 版本起,此函数已弃用。我们强烈建议不要在新代码中使用它。
请改用 `globalPosition()` 或 `y()`。
返回事件发生时鼠标光标的全局 y 坐标。
[deprecated in 6.0] QPointF QMouseEvent::localPos() const
自 6.0 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。
请改用 `position()`。
返回鼠标光标的位置,该位置以QPointF 表示,相对于接收该事件的小部件或项目。
如果因鼠标事件而移动控件,请使用screenPos() 返回的屏幕位置,以避免出现抖动现象。
另请参阅 x()、y()、windowPos() 和screenPos()。
[deprecated in 6.0] QPoint QMouseEvent::pos() const
自 6.0 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。
请改用position()。
返回鼠标光标相对于接收该事件的小部件的位置。
如果因鼠标事件而移动了控件,请使用globalPos() 返回的全局位置,以避免出现抖动现象。
[deprecated in 6.0] QPointF QMouseEvent::screenPos() const
自 6.0 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。
请改用 `globalPosition()`。
返回鼠标光标的位置,该位置以QPointF 表示,相对于接收该事件的屏幕。
另请参阅 x()、y()、pos()、localPos() 和windowPos()。
[deprecated in 6.0] Qt::MouseEventSource QMouseEvent::source() const
自 6.0 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。
请改用 `pointingDevice()`。
返回有关鼠标事件源的信息。
鼠标事件源可用于区分真实的鼠标事件和人工生成的鼠标事件。后者是由操作系统或 Qt 本身根据触摸事件合成的事件。此枚举可告知您事件是从何处合成的;但通常了解事件是从哪个设备合成的更为有用,因此请尽量改用 `pointingDevice()`。
注意:许多 平台不提供此类信息。在这些平台上,始终返回Qt::MouseEventNotSynthesized 。
注意:在基于 Qt 5的代码中 ,source() 常被用于尝试区分实际鼠标事件与因某些旧版QQuickItem 或QWidget 子类未响应QTouchEvent 而合成的事件。然而,您无法分辨事件是来自QTouchEvent 还是QTabletEvent 合成的,且其他信息也会丢失。pointingDevice() 会告知该事件来自哪个具体设备,因此您可以检查pointingDevice()->type() 或pointingDevice()->capabilities() 来决定如何响应此事件。但最好还是直接响应原始事件,而不是仅处理鼠标事件。
另请参阅 Qt::MouseEventSource 和QGraphicsSceneMouseEvent::source()。
[deprecated in 6.0] QPointF QMouseEvent::windowPos() const
自 6.0 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。
请改用scenePosition()。
返回鼠标光标的位置,该位置以QPointF 的形式表示,相对于接收该事件的窗口。
如果因鼠标事件而移动了小部件,请使用globalPos() 返回的全局位置,以避免出现抖动现象。
另请参阅 x()、y()、pos()、localPos() 和screenPos()。
[deprecated in 6.0] int QMouseEvent::x() const
自 6.0 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。
请改用 `position().x()`。
返回鼠标光标的 x 坐标,该坐标相对于接收该事件的控件。
[deprecated in 6.0] int QMouseEvent::y() const
自 6.0 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。
请改用 `position().y()`。
返回鼠标光标的 y 坐标,该坐标以接收该事件的控件为基准。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.