如何在Qml中做一个动作,每次用户触摸屏幕
How to do an action in Qml every time a user touches the screen?
我正在用Qt和Qml编写一个嵌入式linux触摸屏设备的应用程序。
我需要实现一个锁定屏幕,出现在30秒的不活动。
为此,我在c++中实现了一个计时器,它在超时后改变程序的状态。
是否有可能刷新这个定时器在全局范围内每次用户触摸屏幕,这样我就不必调用定时器的start()
插槽在我的程序中的每个可触摸的元素?
我还想刷新这个计时器,即使当用户触摸屏幕的一部分,那里没有按钮/交互元素。
像这样main.qml:
Rectangle {
id: mainRect
width: 800
height: 480
//something like this (oversimplified) pseudo code:
onGlobalUserTouch {
timers.startLockTimer()
}
//end pseudocode
Loader {
id: mainLoader
anchors.fill: parent
source: "FirstPage.qml"
Behavior on opacity {PropertyAnimation{duration:250}}
onLoaded: secondLoader.source = ""
}
states:[
State {
name:"SecondPage"
when: (mainCppClass.state == PanelStates.SECOND_PAGE)
PropertyChanges {
target: mainLoader
source: "SecondPage.qml"
}
}
]
}
我能在网上找到的就是如何在iOS或Android上实现这一点。
如果mainRect是你的根组件,你可以在它的MouseArea中启动计时器。
// touch area of your root component
MouseArea {
anchors.fill: parent
onClicked: {
timers.startLockTimer();
}
// child component
Rectangle {
color: "yellow"
x: 50; y : 50
width: 100; height: 100
}
}
这不会覆盖后代鼠标区域。因此,如果您触摸没有按钮/交互元素的区域,您的startLockTimer将被调用。
相关文章:
- C++如何通过用户输入删除列表元素
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何使用用户输入在C++中正确填充2D数组
- C++MySQL C api用户输入行
- 使用用户定义函数的字符串反转
- 用户定义函数中的指针和输入
- 为什么即使使用-cudart-static进行编译,库用户仍然需要链接到cuda运行时
- 如何只允许用户输入正整数
- C++如何计算用户输入的数字中的偶数位数
- 通过for循环使用用户输入填充列表
- 这是我尝试让用户将值输入到数组中.然后将其隐藏为大量的星号
- 在C++中,我如何接受不同于同一行的用户输入
- 当用户超过按钮点击限制时报告
- 要在Windows上读取/设置用户屏幕保护程序,是否需要使用系统注册表或SystemParametersInfo API
- 如何使用 c++ 打开用户在输出屏幕中提供的文件
- 如何创建桌面图标/按钮来启动用户Windows屏幕保护程序,并设置选项
- 用户输入值,但打印到屏幕的任意值。打印值与输入的值不匹配
- 如何在Qml中做一个动作,每次用户触摸屏幕
- 在c++中,我如何让用户在应用程序窗口外的屏幕上指定一个点(X,Y)
- 在用户关闭bb10(z10)应用程序时,访问主屏幕上的应用程序图标需要很长时间