import QtQuick 2.6;
import QtQuick.Controls 2.1 ;
import QtQuick.Layouts 1.3 ;
Page{
id: page
width: 800
height: 1024
background: Rectangle {
color: "black" ;
anchors.fill:parent ;
}
Rectangle {
id:rect1
x: 0
y:10
width: 100
height: 100
color : "red"
MouseArea {
anchors.fill: parent
onClicked: tmr.restart()
}
}
Rectangle {
id:rect2
x: 0
y:110
width: 100
height: 100
color : "blue"
MouseArea {
anchors.fill: parent
onClicked: tmr.restart()
}
}
Timer {
id : tmr
interval : 30000
repeat : true
running: true
onTriggered: {
console.log ("hello world ")
}
}
}
I develop a software for embedded imx6 freescale device using qt framework.
Basically I just want to restart my timer every time I click and every time I get a touch event on my screen whether the click/touch happen inside the mouse area of my rectangles or outside of them.
The idea is similar to a screensaver.
There are multiple ways, and the right way depends on your requirements.
If you don't need to guarantee that the timer triggers during a input you can just layer a
MouseArea
on top of everything. In thisMouseArea
you handle thepressed
-signals, but dontaccept
them.This allows you to handle the mouse input in the lower layers later. However you only realize whenever a new press happens, and the
Timer
might trigger e.g. during a half-an-hour finger-move input.The second way is to have all
MouseArea
s report uppon their handled signals, that the signal happend, to reset theTimer
. For all unhandled signals, you layer aMouseArea
beneath everything else, handle all signals there to catch what has been falling through.Resorting to C++ you might create a
Item
at the root of yourItem
-tree, and override thechildMouseEventFitler
See my answer here for more on this.
In this case you should add a
MouseArea
right inside thisItem
, so it has something to filter at any place.Thanks to GrecKo I looked into the general
eventFilter
again, and indeed it is really easy.QObject
following the singleton pattern, in which you reimplement theeventFilter
-method, so that it will emit a signalmouseeventspy.h
mouseeventspy.cpp
main.cpp
Timer
main.qml