Reputation: 816
from past 1 week i am trying to solve this issue. i am not able to lock my screen of whatever pages i create. i tried putting timer. but i am not getting how should i detect if the user is not active. for example ex1.qml
rectangle{
id:ex1
color:"red"
keys.onReturnPressed:{
ex2.visble=true;
visible=false;
}
rectangle {
id:ex2
color:"blue"
keys.onReturnPressed:{
visible=false;
ex1.visible=true;
}
}
}
if the user is not active for some time then the application should ask for password the unlock it. if the user is not pressing enter key for 2 mins then it should lock the screen and ask for password. how to do it???
i am waiting for your answer. thanks in advance.
Upvotes: 0
Views: 1180
Reputation: 701
You can try something like this:
FocusScope{
height: 500;
width:500;
focus: true;
Rectangle {
id:ex1
color:"red"
focus: ex1.visible;
visible:true;
anchors.fill: parent;
Keys.onEnterPressed: {
lockTimer.restart();
}
Keys.onReturnPressed:{
lockTimer.restart();
}
}
Rectangle {
id:ex2
color:"blue";
focus: !ex1.visible;
visible: !ex1.visible;
anchors.fill: parent;
Keys.onReturnPressed:{
password.opacity=1;
}
Text {
id: password;
anchors.centerIn: parent
opacity: 0;
text: "Enter Password"
}
}
Timer{
id:lockTimer;
repeat: false;
onTriggered: {
ex2.visible=true;
ex1.visible=false;
}
}
function setTimer(val){
lockTimer.interval=60000*val;
}
Component.onCompleted: {
setTimer(2);
lockTimer.start();
}
}
Upvotes: 1