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::MouseButtonDblClickQEvent::MouseMove 中的一个。

localPos 是鼠标光标相对于接收 widget 或项目的位置。窗口位置将设置为与localPos 相同的值。引起事件的buttonQt::MouseButton 枚举中的一个值。如果事件typeMouseMove ,则该事件的相应按钮是Qt::NoButton 。事件发生时的鼠标和键盘状态由buttonsmodifiers 指定。

globalPosition() 初始化为QCursor::pos() ,这可能并不合适。请使用其他构造函数明确指定全局位置。

[deprecated in 6.0] QPoint QMouseEvent::globalPos() const

自 6.0 版起,该函数已被弃用。我们强烈建议不要在新代码中使用该函数。

请使用globalPosition().toPoint() 代替它。

返回事件发生时鼠标光标的全局位置。这在 X11 等异步窗口系统中非常重要。每当您根据鼠标事件移动部件时,globalPos() 可能与当前指针位置QCursor::pos() 和QWidget::mapToGlobal(pos()) 相差很大。

另请参见 globalX() 和globalY()。

[deprecated in 6.0] int QMouseEvent::globalX() const

自 6.0 版起,该函数已被弃用。我们强烈建议不要在新代码中使用该函数。

请使用globalPosition().x() 代替。

返回事件发生时鼠标光标的全局 x 位置。

另请参阅 globalY() 和globalPos()。

[deprecated in 6.0] int QMouseEvent::globalY() const

自 6.0 版起,该函数已被弃用。我们强烈建议不要在新代码中使用该函数。

请使用globalPosition().y() 代替。

返回事件发生时鼠标指针的全局 y 位置。

另请参阅 globalX() 和globalPos()。

[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() 返回的全局位置,以避免晃动。

另请参阅 x()、y() 和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 XML 5 的代码中,source() 经常被用来尝试区分来自实际鼠标的鼠标事件和那些合成的鼠标事件,因为某些传统的QQuickItemQWidget 子类对QTouchEvent 没有反应。但是,您无法判断它是由QTouchEvent 还是QTabletEvent 合成的,而且会丢失其他信息。pointingDevice()会告诉您它来自哪个特定设备,因此您可以检查pointingDevice()->type()pointingDevice()->capabilities() 来决定如何对这一事件作出反应。但最好是对原始事件做出反应,而不是只处理鼠标事件。

另请参阅 Qt::MouseEventSourceQGraphicsSceneMouseEvent::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 位置。

另请参阅 y() 和pos()。

[deprecated in 6.0] int QMouseEvent::y() const

自 6.0 版起,该函数已被弃用。我们强烈建议不要在新代码中使用该函数。

请使用position().y() 代替它。

返回鼠标指针相对于接收事件的部件的 y 位置。

另请参阅 x() 和pos()。

© 2025 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.