gpt4 book ai didi

android - 通过 MouseArea Qt QML 检测向左或向右滑动

转载 作者:行者123 更新时间:2023-11-29 11:42:04 24 4
gpt4 key购买 nike

我遇到了问题,如何在 qml 中检测通过 MouseArea 的滑动?

此代码,来自文档:

    Rectangle {
id: container
width: 600; height: 200

Rectangle {
id: rect
width: 500; height: 500

MouseArea {
anchors.fill: parent
drag.target: rect
drag.axis: Drag.XAxis
drag.minimumX: 0
drag.maximumX: container.width - rect.width

//event slide here ?
}
}
}

但我不明白如何向左或向右滑动,我在移动应用程序(ios 和 android)中得到了这个用法。

有人可以帮助我吗?谢谢。如何检测用手指向左或向右滑动?谢谢。

最佳答案

就像derM解释的一系列事件:Touch -> Movement -> Release
这是我对这个概念的解决方案。工作得很好!!

MouseArea {
width: 100
height: 50
preventStealing: true
property real velocity: 0.0
property int xStart: 0
property int xPrev: 0
property bool tracing: false
onPressed: {
xStart = mouse.x
xPrev = mouse.x
velocity = 0
tracing = true
console.log( " pressed "+xStart)
console.log( " pressed "+xPrev)
}
onPositionChanged: {
if ( !tracing ) return
var currVel = (mouse.x-xPrev)
velocity = (velocity + currVel)/2.0
xPrev = mouse.x
if ( velocity > 15 && mouse.x > parent.width*0.2 ) {
tracing = false
console.log( " positioned ")
// SWIPE DETECTED !! EMIT SIGNAL or DO your action
}
}
onReleased: {
tracing = false
if ( velocity > 15 && mouse.x > parent.width*0.2 ) {
// SWIPE DETECTED !! EMIT SIGNAL or DO your action
console.log("abcccccccccc")
}
}
}
}

关于android - 通过 MouseArea Qt QML 检测向左或向右滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45916047/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com