lock touch screen
-
Hello, everyone.
I have coded a gui using qml and deploy it rpi3b+. there is a touch screen to interact with the user. I need to have lock screen functionality. However, I couldn't find a solution to do this!
is there any way?
any suggestion is greatly appreciated.
Regards -
@jsulm said in lock touch screen:
@imhs By "lock" you mean disable touch? Do you want to disable it permanently or when needed and then enable it again? What is the use case for that?
@jsulm
Thanks for your response.In fact, I want to disable all the buttons when the screen is locked to prevent accidental touch (since this UI controls some hardware) and enable them again when I toggle off the lock switch.
-
@J-Hilk said in lock touch screen:
@imhs
you mean, you want to start the systems screen lock, so that the user has to reenter his Password ?You can't do that from qt, maybe there's a native c lib that allows you to do it, but I'm not aware of it.
I don't need a password to be entered again. Just a simple lock to block touch events.
-
@imhs You can call https://doc.qt.io/qt-5/qwidget.html#setDisabled on your central widget or main window.
-
@jsulm said in lock touch screen:
@imhs You can call https://doc.qt.io/qt-5/qwidget.html#setDisabled on your central widget or main window.
Thanks for your response. But if I am not wrong, it is for Qwidget applications. I have used qml.
Is there any similar function in qml?
regards. -
@J-Hilk said in lock touch screen:
@imhs
enabled = false (on the root element of your application)There is no property "enabled" in my root element which is "window".
here is the first lines of my codeimport QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.VirtualKeyboard 2.4 import QtQuick.Controls 2.5 //import QtQuick.Controls 2.13 //import QtQuick.Controls 1.4 import QtQuick.Layouts 1.3 import Modbus.Backend 1.0 import QtQuick.Extras 1.4 import QtQuick.Controls.Styles 1.4 import Qt.labs.settings 1.0 import QtQuick.Window 2.3 import QtQuick.Dialogs 1.3 //import "delayfunc.js" as Mydelay //import "content" //import "content" Window { id: window visible: true width: 800 height: 480 title: qsTr("Process Control") .... }
other elements are inside this.
-
@imhs
ah Window is special, I forgotA hacky way could be a simply MouseArea to capture the input ?
MouseArea{
id:blockAllInput
anchors.fill: parent
enabled: false
z:100 //to make sure, its above it siblings
}enable the MouseAre to capture all input disable it for normal function...
-
@J-Hilk said in lock touch screen:
@imhs
ah Window is special, I forgotA hacky way could be a simply MouseArea to capture the input ?
MouseArea{
id:blockAllInput
anchors.fill: parent
enabled: false
z:100 //to make sure, its above it siblings
}enable the MouseAre to capture all input disable it for normal function...
Thanks a lot. It works.
But is also prevent me to touch my lock switch again to disable it. -
please find the code below:
GroupBox { id: buttons y:3 //title: "Row layout" anchors.left: parent.left width: parent.width height: 40 background: Rectangle { anchors.fill: parent opacity: 0.1 color: "black" radius: 10 } Rectangle{ anchors.fill:parent color: "transparent" // MouseArea{ // anchors.fill: parent // cursorShape: Qt.BlankCursor // } Switch{ id:runStop_switch //text: qsTr("Switch") x:3//temp_box.x y: -5//temp_box.y checked: false signal mytoggle //onMytoggle: indicator: Rectangle { implicitWidth: 40 implicitHeight: 20 x:runStop_switch.leftPadding y:parent.height / 2 - height / 2+2 radius: 13 opacity: 0.9 color: runStop_switch.checked ? "yellow" : "#ffffff" border.color: runStop_switch.checked ? "#17a81a" : "#cccccc" Rectangle { x: runStop_switch.checked ? parent.width - width : 0 y:0 width: 20 height: 20 radius: 23 color: runStop_switch.down ? "#cccccc" : "#ffffff" border.color: runStop_switch.checked ? (runStop_switch.down ? "#17a81a" : "#21be2b") : "#999999" } } contentItem: Text { text: runStop_switch.text font: runStop_switch.font opacity: enabled ? 1.0 : 0.3 color: runStop_switch.down ? "#17a81a" : "#21be2b" verticalAlignment: Text.AlignVCenter leftPadding: runStop_switch.indicator.width + runStop_switch.spacing } //onToggled: { onCheckedChanged: { if (runStop_switch.checked==true){ rusStop_label.text="Run"; modbus_connection.Read(); setpoint_slider_value.running=true if (setpoint_slider.value0!=setpoint_slider.value){ modbus_connection.setStPnt(textField_setPnt.value/100) } temp_switch.checked=false temp_switch.toggle() motor0_switch.checked=false motor0_switch.toggle() motor1_switch.checked=false motor1_switch.toggle() motor2_switch.checked=false motor2_switch.toggle() motor3_switch.checked=false motor3_switch.toggle() motor4_switch.checked=false motor4_switch.toggle() motor5_switch.checked=false motor5_switch.toggle() motor6_switch.checked=false motor6_switch.toggle() if(motor0_switch.checked==true){ motor0.value=motor0.mymotor0_val modbus_connection.setCell0(motor0.value) } if(motor1_switch.checked==true){ motor1.value=motor1.mymotor1_val modbus_connection.setCell1(motor1.value) } if(motor2_switch.checked==true){ motor2.value=motor2.mymotor2_val modbus_connection.setCell2(motor2.value) } if(motor3_switch.checked==true){ motor3.value=motor3.mymotor3_val modbus_connection.setDuall_cell(motor3.value) } if(motor4_switch.checked==true){ motor4.value=motor4.mymotor4_val modbus_connection.setCell4(motor4.value) } if(motor5_switch.checked==true){ motor5.value=motor5.mymotor5_val modbus_connection.setCell5(motor5.value) } if(motor6_switch.checked==true){ motor6.value=motor6.mymotor6_val modbus_connection.setCell6(motor6.value) } pump_switch.checked=false pump_switch.toggle() if(pump_switch.checked==true){ if (pump.mypump_val<150) pump.value=150 else pump.value=pump.mypump_val modbus_connection.setPump(pump.value) } status_timer.stop() modbus_connection.setStatus("System is running") status_bar_text.counter=3 status_timer.start() modbus_connection.setStatus(" ") } else{ // modbus_connection.setStatus(" ") modbus_connection.Disconect(); temp_switch.checked=true // cooling_label.visible=false; // heating_label.visible=false; setpoint_slider_value.running=false temp_switch.toggle() motor0_switch.checked=true motor0_switch.toggle() if(motor0_switch.checked==false){ motor0.value=0 } motor1_switch.checked=true motor1_switch.toggle() if(motor1_switch.checked==false){ motor1.value=0 } motor2_switch.checked=true motor2_switch.toggle() if(motor2_switch.checked==false){ motor2.value=0 } motor3_switch.checked=true motor3_switch.toggle() if(motor3_switch.checked==false){ motor3.value=0 } motor4_switch.checked=true motor4_switch.toggle() if(motor4_switch.checked==false){ motor4.value=0 } motor5_switch.checked=true motor5_switch.toggle() if(motor5_switch.checked==false){ motor5.value=0 } motor6_switch.checked=true motor6_switch.toggle() if(motor6_switch.checked==false){ motor6.value=0 } pump_switch.checked=true pump_switch.toggle() if(pump_switch.checked==false){ pump.value=0 } status_bar_text.counter=3 status_timer.start() rusStop_label.text="Stop" status_timer.stop() modbus_connection.setStatus("System has been stopped") status_timer.stop() // console.log("Stop") } } } Label { id:rusStop_label width: 40 x:runStop_switch.x+2 y:runStop_switch.y-5 visible: true color: "white" horizontalAlignment: Text.AlignHCenter text: "Stop" font.pixelSize: 12 } Label{ id: state_title x: heating_cooling.x+20 y:30 text:"State" color: "white" font.bold: true font.pixelSize: 12 } Switch{ id:lock_switch //text: qsTr("Unlock") x:725//temp_box.x y: -5//temp_box.y checked: false indicator: Rectangle { implicitWidth: 40 implicitHeight: 20 x:lock_switch.leftPadding y:parent.height / 2 - height / 2+2 radius: 13 opacity: 0.9 color: lock_switch.checked ? "yellow" : "#ffffff" border.color: lock_switch.checked ? "#17a81a" : "#cccccc" Rectangle { x: lock_switch.checked ? parent.width - width : 0 y:0 width: 20 height: 20 radius: 23 color: lock_switch.down ? "#cccccc" : "#ffffff" border.color: lock_switch.checked ? (lock_switch.down ? "#17a81a" : "#21be2b") : "#999999" } } contentItem: Text { text: lock_switch.text font: lock_switch.font opacity: enabled ? 1.0 : 0.3 color: lock_switch.down ? "#17a81a" : "#21be2b" verticalAlignment: Text.AlignVCenter leftPadding: lock_switch.indicator.width + lock_switch.spacing } onCheckedChanged: { // onToggled: { if (lock_switch.checked==true){ lock_label.text="Locked" date.enabled=false rdioBut_external.enabled=false rdioBut_internal.enabled=false temp_switch.enabled=false motor0_switch.enabled=false motor1_switch.enabled=false motor2_switch.enabled=false motor3_switch.enabled=false motor4_switch.enabled=false motor5_switch.enabled=false motor6_switch.enabled=false pump_switch.enabled=false pwm_slider.enabled=false setpoint_slider.enabled=false rdioBut_motor0.enabled=false rdioBut_motor1.enabled=false rdioBut_motor2.enabled=false rdioBut_motor3.enabled=false rdioBut_motor4.enabled=false rdioBut_motor5.enabled=false rdioBut_motor6.enabled=false rdioBut_pump.enabled=false pump_select.enabled=false motor0_select.enabled=false motor1_select.enabled=false motor2_select.enabled=false motor3_select.enabled=false motor4_select.enabled=false motor5_select.enabled=false motor6_select.enabled=false runStop_switch.enabled=false textField_setPnt.enabled=false pwm_slider_spinbox.enabled=false modbus_connection.setStatus(" ") status_timer.stop() modbus_connection.setStatus("Screen is locked") status_bar_text.counter=5 status_timer.start() // // console.log("Screen is locked ") } else{ lock_label.text="Unlocked" date.enabled=true rdioBut_external.enabled=true rdioBut_internal.enabled=true temp_switch.enabled=true motor0_switch.enabled=true motor1_switch.enabled=true motor2_switch.enabled=true motor3_switch.enabled=true motor4_switch.enabled=true motor5_switch.enabled=true motor6_switch.enabled=true pump_switch.enabled=true pwm_slider.enabled=true setpoint_slider.enabled=true rdioBut_motor0.enabled=true rdioBut_motor1.enabled=true rdioBut_motor2.enabled=true rdioBut_motor3.enabled=true rdioBut_motor4.enabled=true rdioBut_motor5.enabled=true rdioBut_motor6.enabled=true rdioBut_pump.enabled=true pump_select.enabled=true motor0_select.enabled=true motor1_select.enabled=true motor2_select.enabled=true motor3_select.enabled=true motor4_select.enabled=true motor5_select.enabled=true motor6_select.enabled=true runStop_switch.enabled=true textField_setPnt.enabled=true pwm_slider_spinbox.enabled=true modbus_connection.setStatus(" ") status_timer.stop() modbus_connection.setStatus("Screen is unlocked") status_bar_text.counter=5 status_timer.start() // // console.log("Screen is unlocked") } } } Label { id:lock_label width: 40 x:lock_switch.x+2 y:lock_switch.y-5 visible: true color: "white" text: "Unlocked" horizontalAlignment: Text.AlignHCenter font.pixelSize: 12 } } }
-
@imhs
ah yesrunStop_switch
is not a sibling of the mouse area, as it's a child ofbuttons
thez
property only effects the siblings hierarchytry:
MouseArea{ id:blockAllInput anchors.fill: parent z: 100 onPressed: { var adjusted = mapToItem(blockAllInput, runStop_switch.x, runStop_switch.y) if(mouseX > adjusted.x && mouseX < adjusted.x + runStop_switch.width) if(mouseY > adjusted.y && mouseY < adjusted.y + runStop_switch.height) mouse.accepted = false } }
that should let the pressed signal through, but not the release, so clicked will not be emitted š¤
You'll have to adjust that -
@J-Hilk said in lock touch screen:
MouseArea{
id:blockAllInput
anchors.fill: parent
z: 100
onPressed: {
var adjusted = mapToItem(blockAllInput, runStop_switch.x, runStop_switch.y)
if(mouseX > adjusted.x && mouseX < adjusted.x + runStop_switch.width)
if(mouseY > adjusted.y && mouseY < adjusted.y + runStop_switch.height)
mouse.accepted = false
}
}Thank you so much. You gave me the clue. I appreciate your kind help.