Detect Mouse Press&Hold Release
-
Hi All,
i'm trying to detect the mouse press& hold as well as mouse press & hold release .
But i'm unable to detect press& hold release event.Timer{
id:qkSpinDownTimer
interval: 200
running: false
repeat:trueonTriggered: { console.log("Inside the timer Down of spinner") rotatedAntiClockwise(icompID,strType) } } Rectangle{ id:qk_down_arrow width:100 height:87 // visible:false border.width:1 // border.color:"#2a2a2a" color:"#616161" state:"ArrowStateACtive" anchors.top:qk_up_arrow.bottom
// anchors.right:text1.right
Image{
width:30
height:30
anchors.centerIn:parent
source: qkDownArrowImage
}MouseArea{ anchors.fill:parent onClicked: { console.log("Arrow Key down clicked \n"); //state="ArrowStateSelected" rotateAntiClockwise(icompID,strType) } onPressAndHold: { console.log("on press and hold") qkSpinDownTimer.running=true; qkSpinDownTimer.start(); } onPressed: { parent.color="blue" } onReleased: { parent.color="gray" qkSpinDownTimer.running=false; qkSpinDownTimer.stop(); } } }
-
hi @Madesh-R
for me I am able to detect press and hold, pressed and clicked
import QtQuick 2.9
import QtQuick.Window 2.2Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Rectangle {color:"RED" width:200 height:200 anchors.centerIn: parent MouseArea { anchors.fill:parent onClicked: { console.log("clicked"); } onPressed: { console.log("pressed") } onPressAndHold: { console.log("pressed and hold") } } } }
output
QML debugging is enabled. Only use this in a safe environment. qml: pressed qml: clicked qml: pressed qml: pressed and hold
I think this is the thing you were asking for?
-
Thanks for the reply.
Let me state the problem very clearly.
On press and hold of mouse button , i want to start the timer. And Should stop it when it is released.
I'm getting the expected behaviour on doing separately for a single component.But with timers, I'm unable to do so. -
hi
try this
I defined a timer here and on mouse pressandHold timer is getting started and prints a message and when mouse is released it will stop timer and printing of message will also stop.import QtQuick 2.9 import QtQuick.Window 2.2 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Rectangle { width:100 height:100 color:"red" MouseArea {anchors.fill:parent onPressAndHold: { ash.running=true } onReleased: { ash.running=false } } } Timer {id:ash interval: 500; running: false; repeat: true onTriggered: console.log("started") } }
-
@Madesh-R Hi,
just start your timer in onPressed and stop it by calling in onReleasedonPressed: {
qkSpinDownTimer.running=true; qkSpinDownTimer.start();
parent.color="blue" } onReleased: { parent.color="gray" qkSpinDownTimer.running=false; qkSpinDownTimer.stop(); }
After PressAndHold signal, onreleased signal never called.