MultiPointTouchArea QML Type
可处理多个触摸点。更多
Import Statement: | import QtQuick |
Inherits: |
属性
- maximumTouchPoints : int
- minimumTouchPoints : int
- mouseEnabled : bool
- touchPoints : list<TouchPoint>
信号
- canceled(list<TouchPoint> touchPoints)
- gestureStarted(GestureEvent gesture)
- pressed(list<TouchPoint> touchPoints)
- released(list<TouchPoint> touchPoints)
- touchUpdated(list<TouchPoint> touchPoints)
- updated(list<TouchPoint> touchPoints)
详细说明
MultiPointTouchArea 是用于跟踪多个触摸点的不可见项。
Item::enabled 属性用于启用或禁用触摸处理。禁用时,触摸区域对鼠标和触摸事件透明。
默认情况下,鼠标的处理方式与单个触摸点相同,触摸区域下的项目不会收到鼠标事件,因为触摸区域正在处理这些事件。但是,如果mouseEnabled 属性设置为 false,它就会对鼠标事件透明,这样就可以使用另一个鼠标敏感项(如MouseArea )单独处理鼠标交互。
MultiPointTouchArea 有两种使用方法:
- 设置
touchPoints
,为触摸点对象提供可绑定到以下对象的属性 - 使用 onTouchUpdated 或 onPressed、onUpdated 和 onReleased 处理程序
虽然 MultiPointTouchArea可以独占某些触摸点,但也可以同时激活多个 MultiPointTouchAreas,每个 MultiPointTouchAreas 对一组不同的触摸点进行操作。
另请参阅 TouchPoint 。
属性文档
这些属性包含触摸区域要处理的触摸点范围。
例如,您可以使用嵌套的 MultiPointTouchAreas(多点触摸区域),其中一个处理两个手指触摸,另一个处理三个手指触摸。
默认情况下,触摸区域内的所有触摸点都会被处理。
如果mouseEnabled 为 true,鼠标将作为一个触摸点,因此它也受这些约束条件的限制:例如,如果maximumTouchPoints 为 2,您可以将鼠标作为一个触摸点,将手指作为另一个触摸点,总共两个触摸点。
mouseEnabled : bool |
该属性控制MultiPointTouchArea 是否也会处理鼠标事件。如果为 true(默认值),触摸区域将把鼠标视为单个触摸点;如果为 false,触摸区域将忽略鼠标事件,允许它们 "通过",以便由下面的其他项目处理。
touchPoints : list<TouchPoint> |
该属性包含一组可绑定的用户定义触摸点对象。
如果mouseEnabled 为 true(默认值),且鼠标位于触摸区域上方时按下鼠标左键,则当前鼠标位置将成为这些触摸点之一。
在下面的示例中,我们有两个小矩形跟随我们的触摸点。
import QtQuick Rectangle { width: 400; height: 400 MultiPointTouchArea { anchors.fill: parent touchPoints: [ TouchPoint { id: point1 }, TouchPoint { id: point2 } ] } Rectangle { width: 30; height: 30 color: "green" x: point1.x y: point1.y } Rectangle { width: 30; height: 30 color: "yellow" x: point2.x y: point2.y } }
默认情况下,此属性为空列表。
另请参阅 TouchPoint 。
信号文档
canceled(list<TouchPoint> touchPoints) |
当新的触摸事件因另一个项目抢占了触摸事件处理权而被取消时,将发出该信号。
此信号用于高级用途:当处理输入的MultiPointTouchArea 不止一个,或Flickable 内有一个MultiPointTouchArea 时,此信号非常有用。在后一种情况下,如果您在onPressed
信号处理程序中执行了某些逻辑,然后开始拖动,Flickable 可能会从MultiPointTouchArea 中窃取触摸处理。在这些情况下,当MultiPointTouchArea 失去对Flickable 的触摸处理时,为了重置逻辑,除了处理released 外,还应该处理canceled
。
touchPoints 是取消点列表。
注: 如果您在信号处理程序代码中使用touchPoints
参数,最好在正式参数中重新命名,以免与touchPoints
属性混淆(见QML 编码约定):
onCanceled: (points) => console.log("canceled", points.length)
注: 相应的处理程序是onCanceled
。
gestureStarted(GestureEvent gesture) |
当达到全局拖动阈值时,将发出该信号。
当MultiPointTouchArea 嵌套在 Flickable 或另一个MultiPointTouchArea 中时,通常会使用此信号。达到阈值并处理该信号后,您可以确定触摸区域是否应抓取当前的触摸点。默认情况下,它们不会被抓取;要抓取它们,请调用gesture.grab()
。如果不抓取手势,嵌套的 Flickable 等也有机会抓取。
gesture 对象还包括当前touchPoints
和dragThreshold
的信息。
注: 相应的处理程序是onGestureStarted
。
pressed(list<TouchPoint> touchPoints) |
touchPoints 是这些新点的列表。
如果minimumTouchPoints 设置为大于 1 的值,则在达到所需的最小触摸点数之前,不会发出此信号。
注: 如果您在信号处理程序代码中使用touchPoints
参数,最好在正式参数中重新命名,以免与touchPoints
属性混淆(请参阅QML 编码约定):
onPressed: (points) => console.log("pressed", points.length)
注: 相应的处理程序是onPressed
。
released(list<TouchPoint> touchPoints) |
touchPoints 是这些已移除点的列表。
注: 如果您在信号处理程序代码中使用touchPoints
参数,最好在正式参数中重命名它,以免与touchPoints
属性混淆(见QML Coding Conventions):
onReleased: (points) => console.log("released", points.length)
注: 相应的处理程序是onReleased
。
touchUpdated(list<TouchPoint> touchPoints) |
当MultiPointTouchArea 处理的触摸点发生变化时,就会发出该信号。这包括添加新的触摸点、删除或取消以前的触摸点,以及更新当前的触摸点数据。touchPoints 是当前所有触摸点的列表。
注: 相应的处理程序是onTouchUpdated
。
updated(list<TouchPoint> touchPoints) |
touchPoints 是这些更新点的列表。
注: 如果您在信号处理程序代码中使用touchPoints
参数,最好在正式参数中重新命名,以免与touchPoints
属性混淆(见QML 编码约定):
onUpdated: (points) => console.log("updated", points.length)
注: 相应的处理程序是onUpdated
。
© 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.