MouseEvent QML Type (Uncreatable)
提供有关鼠标事件的信息。更多...
| Import Statement: | import QtQuick |
注意:这是一个不可创建的类型。无法在 QML 中对其进行实例化。
属性
- accepted : bool
- button : enumeration
- buttons : int
- flags : int
- modifiers : int
- wasHeld : bool
- x : real
- y : real
详细说明
可以通过x 和y 属性获取鼠标的位置。可以通过button 属性获取触发该事件的按钮。
另请参阅 MouseArea 。
属性文档
accepted : bool
将accepted 设置为true可阻止鼠标事件传播到该项下方的项目。
通常,如果该项对鼠标事件进行了处理,则应接受该事件,以避免堆叠顺序中位于其下方的项也对同一事件做出响应。
button : enumeration [read-only]
该属性保存了触发该事件的按钮。它可以是以下之一:
buttons : int [read-only]
该属性存储事件发生时被按下的鼠标按钮。对于鼠标移动事件,此处指所有被按下的按钮;对于鼠标按下和双击事件,此处包括触发该事件的按钮;对于鼠标释放事件,此处不包括触发该事件的按钮。
它包含以下按钮的位运算组合:
flags : int [read-only]
该属性包含提供有关鼠标事件附加信息的标志。
- Qt.MouseEventCreatedDoubleClick - 表示 Qt 已根据此事件生成了一个双击事件。该标志仅在源自按钮按下的事件中被设置,而在由此产生的双击事件中则不会被设置。
modifiers : int [read-only]
该属性保存了事件发生前瞬间存在的键盘修饰符标志。
它包含以下选项的按位组合:
- Qt.NoModifier - 未按下任何修饰键。
- Qt.ShiftModifier - 键盘上的 Shift 键被按下。
- Qt.ControlModifier - 键盘上的 Ctrl 键被按下。
- Qt.AltModifier - 键盘上的 Alt 键被按下。
- Qt.MetaModifier - 按下了键盘上的 Meta 键。
- Qt.KeypadModifier - 按下了数字小键盘上的按键。
例如,要响应 Shift 键 + 鼠标左键点击的操作:
MouseArea {
onClicked: (mouse)=> {
if ((mouse.button == Qt.LeftButton) && (mouse.modifiers & Qt.ShiftModifier))
doSomething();
}
}wasHeld : bool [read-only]
如果鼠标按钮按下的时间超过阈值(800 毫秒),则该属性为真。
这些属性存储了鼠标事件提供的坐标。
© 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.