Reputation: 4561
I checked the different mouseArea events in the documentation and there is no chance to execute a js function while a mouseArea is being pressed.
As I am not finding a direct way, so I went for this workaround.
I set a Timer to update my panel in case the added bool property isPressed
of my mousearea is set to true.
Mouse area:
MouseArea {
id: myMouseArea
//pos and size removed. Not relevant
property bool isPressed: false
onPressed: {
isPressed = true;
}
onReleased: {
isPressed = false;
}
}
Timer:
Timer {
id: updatePanelTimer
interval: 100
repeat: true
running: true
triggeredOnStart: true
onTriggered: updatePanel()
}
Function:
function updatePanel() {
if (myMouseArea.isPressed) {
//run code
}
}
Is there a more direct way to have a code executed while a mouseArea is being pressed? I would like to know if there is a way to do this whithin the mouseArea itself, mainly if its possible without the need of the timer.
Upvotes: 0
Views: 389
Reputation: 1514
If you want to run code only while mouse is in pressed state :
MouseArea {
id: myMouseArea
//pos and size removed. Not relevant
property bool isPressed: false
onPressed: {
updatePanelTimer.start()
}
onReleased: {
updatePanelTimer.stop()
}
}
Upvotes: 1