Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. lock touch screen
Forum Updated to NodeBB v4.3 + New Features

lock touch screen

Scheduled Pinned Locked Moved Solved QML and Qt Quick
17 Posts 3 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imhs
    wrote on last edited by
    #1

    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

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • I imhs

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 1 Reply Last reply
      2
      • I imhs

        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

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @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.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        I 1 Reply Last reply
        1
        • jsulmJ jsulm

          @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?

          I Offline
          I Offline
          imhs
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @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 Offline
            I Offline
            imhs
            wrote on last edited by
            #5

            @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.

            jsulmJ 1 Reply Last reply
            0
            • I imhs

              @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.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @imhs You can call https://doc.qt.io/qt-5/qwidget.html#setDisabled on your central widget or main window.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              I 1 Reply Last reply
              3
              • jsulmJ jsulm

                @imhs You can call https://doc.qt.io/qt-5/qwidget.html#setDisabled on your central widget or main window.

                I Offline
                I Offline
                imhs
                wrote on last edited by
                #7

                @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.HilkJ 1 Reply Last reply
                0
                • I imhs

                  @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.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  @imhs
                  enabled = false (on the root element of your application)


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  I 1 Reply Last reply
                  1
                  • J.HilkJ J.Hilk

                    @imhs
                    enabled = false (on the root element of your application)

                    I Offline
                    I Offline
                    imhs
                    wrote on last edited by
                    #9

                    @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 code

                    import 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.

                    J.HilkJ 1 Reply Last reply
                    0
                    • I imhs

                      @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 code

                      import 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.

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #10

                      @imhs
                      ah Window is special, I forgot

                      A 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...


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      I 1 Reply Last reply
                      2
                      • J.HilkJ J.Hilk

                        @imhs
                        ah Window is special, I forgot

                        A 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...

                        I Offline
                        I Offline
                        imhs
                        wrote on last edited by
                        #11

                        @J-Hilk said in lock touch screen:

                        @imhs
                        ah Window is special, I forgot

                        A 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.

                        J.HilkJ 1 Reply Last reply
                        0
                        • I imhs

                          @J-Hilk said in lock touch screen:

                          @imhs
                          ah Window is special, I forgot

                          A 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.

                          J.HilkJ Offline
                          J.HilkJ Offline
                          J.Hilk
                          Moderators
                          wrote on last edited by
                          #12

                          @imhs
                          if the lock switch is also in main.qml, simply give it a z of > 100
                          šŸ˜‰


                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                          Q: What's that?
                          A: It's blue light.
                          Q: What does it do?
                          A: It turns blue.

                          I 1 Reply Last reply
                          1
                          • J.HilkJ J.Hilk

                            @imhs
                            if the lock switch is also in main.qml, simply give it a z of > 100
                            šŸ˜‰

                            I Offline
                            I Offline
                            imhs
                            wrote on last edited by
                            #13

                            @J-Hilk said in lock touch screen:

                            @imhs
                            if the lock switch is also in main.qml, simply give it a z of > 100
                            šŸ˜‰

                            It is in the main.qml but it is not a child of the root (window). I tried it before my last post but it doesn't work.

                            J.HilkJ 1 Reply Last reply
                            0
                            • I imhs

                              @J-Hilk said in lock touch screen:

                              @imhs
                              if the lock switch is also in main.qml, simply give it a z of > 100
                              šŸ˜‰

                              It is in the main.qml but it is not a child of the root (window). I tried it before my last post but it doesn't work.

                              J.HilkJ Offline
                              J.HilkJ Offline
                              J.Hilk
                              Moderators
                              wrote on last edited by
                              #14

                              @imhs mmh,
                              can you show that part of the main.qml ?


                              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                              Q: What's that?
                              A: It's blue light.
                              Q: What does it do?
                              A: It turns blue.

                              1 Reply Last reply
                              0
                              • I Offline
                                I Offline
                                imhs
                                wrote on last edited by
                                #15

                                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
                                            }
                                
                                
                                        }
                                
                                
                                    }
                                
                                J.HilkJ 1 Reply Last reply
                                0
                                • I imhs

                                  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
                                              }
                                  
                                  
                                          }
                                  
                                  
                                      }
                                  
                                  J.HilkJ Offline
                                  J.HilkJ Offline
                                  J.Hilk
                                  Moderators
                                  wrote on last edited by J.Hilk
                                  #16

                                  @imhs
                                  ah yes runStop_switch is not a sibling of the mouse area, as it's a child of buttons the z property only effects the siblings hierarchy

                                  try:

                                  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


                                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                  Q: What's that?
                                  A: It's blue light.
                                  Q: What does it do?
                                  A: It turns blue.

                                  I 1 Reply Last reply
                                  1
                                  • J.HilkJ J.Hilk

                                    @imhs
                                    ah yes runStop_switch is not a sibling of the mouse area, as it's a child of buttons the z property only effects the siblings hierarchy

                                    try:

                                    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

                                    I Offline
                                    I Offline
                                    imhs
                                    wrote on last edited by
                                    #17

                                    @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.

                                    1 Reply Last reply
                                    1

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved