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. Time Edit field in QML
Forum Updated to NodeBB v4.3 + New Features

Time Edit field in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qtquick2textfieldqtquickcontrol
13 Posts 5 Posters 7.0k Views 3 Watching
  • 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.
  • P Offline
    P Offline
    pra7
    wrote on 15 Sept 2017, 19:14 last edited by
    #1

    I need to implement a TimeEdit(HH:MM:SS) field in QML similar to QTimeEdit in QT C++. In QML I didn't find TimeEdit and I have implemented the control similar to TimeEdit using TextField and if I add inputMask then the Regular expression is not at all validated, Is there any way that I can achieve this? Following is the code.

    import QtQuick 2.7
        import QtQuick.Window 2.2
        import QtQuick.Controls 2.2
        
        Window {
            visible: true
            width: 640
            height: 480
            title: qsTr("Time Edit")
        
            TextField{
                id:textEditTD
                text : ""
                inputMethodHints: Qt.ImhDigitsOnly
        
                inputMask: "dd:dd:dd; "
                validator: RegExpValidator { regExp: /^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):[0-5][0-9]$ / }
        
                width:100
                height:50
                background:Rectangle{
                    color:"transparent"
                    border.color: "red"
                    border.width:2
                    radius:(width * 0.05)
                }
            }
        }
    
    
    M 1 Reply Last reply 15 Sept 2017, 20:55
    0
    • P pra7
      15 Sept 2017, 19:14

      I need to implement a TimeEdit(HH:MM:SS) field in QML similar to QTimeEdit in QT C++. In QML I didn't find TimeEdit and I have implemented the control similar to TimeEdit using TextField and if I add inputMask then the Regular expression is not at all validated, Is there any way that I can achieve this? Following is the code.

      import QtQuick 2.7
          import QtQuick.Window 2.2
          import QtQuick.Controls 2.2
          
          Window {
              visible: true
              width: 640
              height: 480
              title: qsTr("Time Edit")
          
              TextField{
                  id:textEditTD
                  text : ""
                  inputMethodHints: Qt.ImhDigitsOnly
          
                  inputMask: "dd:dd:dd; "
                  validator: RegExpValidator { regExp: /^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):[0-5][0-9]$ / }
          
                  width:100
                  height:50
                  background:Rectangle{
                      color:"transparent"
                      border.color: "red"
                      border.width:2
                      radius:(width * 0.05)
                  }
              }
          }
      
      
      M Offline
      M Offline
      mostefa
      wrote on 15 Sept 2017, 20:55 last edited by mostefa
      #2

      @pra7

      Hi @pra7

      Your code is correct but you have to add an input mask also

      inputMask: "99:99:99"//input mask
      text: "00:00:00" //default text
      

      Your code will code to something like this:

      import QtQuick 2.7
          import QtQuick.Window 2.2
          import QtQuick.Controls 2.2
      
          Window {
              visible: true
              width: 640
              height: 480
              title: qsTr("Time Edit")
      
              TextField{
                  id:textEditTD
                  text : "00:00:00"
                  inputMask: "99:99:99"
                  inputMethodHints: Qt.ImhDigitsOnly
                  validator: RegExpValidator { regExp: /^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):[0-5][0-9]$ / }
      
                  width:100
                  height:50
                  background:Rectangle{
                      color:"transparent"
                      border.color: "red"
                      border.width:2
                      radius:(width * 0.05)
                  }
              }
          }
      

      This should work ...

      P 1 Reply Last reply 16 Sept 2017, 08:33
      1
      • M mostefa
        15 Sept 2017, 20:55

        @pra7

        Hi @pra7

        Your code is correct but you have to add an input mask also

        inputMask: "99:99:99"//input mask
        text: "00:00:00" //default text
        

        Your code will code to something like this:

        import QtQuick 2.7
            import QtQuick.Window 2.2
            import QtQuick.Controls 2.2
        
            Window {
                visible: true
                width: 640
                height: 480
                title: qsTr("Time Edit")
        
                TextField{
                    id:textEditTD
                    text : "00:00:00"
                    inputMask: "99:99:99"
                    inputMethodHints: Qt.ImhDigitsOnly
                    validator: RegExpValidator { regExp: /^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):[0-5][0-9]$ / }
        
                    width:100
                    height:50
                    background:Rectangle{
                        color:"transparent"
                        border.color: "red"
                        border.width:2
                        radius:(width * 0.05)
                    }
                }
            }
        

        This should work ...

        P Offline
        P Offline
        Praveen_2017
        wrote on 16 Sept 2017, 08:33 last edited by Praveen_2017
        #3

        @mostefa Thanks it almost works but backspace is not working.
        For Example : If i enter 12:12:12 and try to clear the value using backspace then it's not working. My expectation is that it should become 00:00:00. Is there any way to achieve this ?

        M 1 Reply Last reply 16 Sept 2017, 09:41
        0
        • P Praveen_2017
          16 Sept 2017, 08:33

          @mostefa Thanks it almost works but backspace is not working.
          For Example : If i enter 12:12:12 and try to clear the value using backspace then it's not working. My expectation is that it should become 00:00:00. Is there any way to achieve this ?

          M Offline
          M Offline
          mostefa
          wrote on 16 Sept 2017, 09:41 last edited by
          #4

          @Praveen_2017 said in Time Edit field in QML:

          @mostefa Thanks it almost works but backspace is not working.
          For Example : If i enter 12:12:12 and try to clear the value using backspace then it's not working. My expectation is that it should become 00:00:00. Is there any way to achieve this ?

          Hi @Praveen_2017

          What if you match backspace for each digits in your expressions?

          You have to change your regExp on your validator to something like this:

          validator: RegExpValidator { regExp: /^([0-1\s]?[0-9\s]|2[0-3\s]):([0-5\s][0-9\s]):([0-5\s][0-9\s])$ / }
          
          P P 2 Replies Last reply 16 Sept 2017, 10:03
          1
          • M mostefa
            16 Sept 2017, 09:41

            @Praveen_2017 said in Time Edit field in QML:

            @mostefa Thanks it almost works but backspace is not working.
            For Example : If i enter 12:12:12 and try to clear the value using backspace then it's not working. My expectation is that it should become 00:00:00. Is there any way to achieve this ?

            Hi @Praveen_2017

            What if you match backspace for each digits in your expressions?

            You have to change your regExp on your validator to something like this:

            validator: RegExpValidator { regExp: /^([0-1\s]?[0-9\s]|2[0-3\s]):([0-5\s][0-9\s]):([0-5\s][0-9\s])$ / }
            
            P Offline
            P Offline
            Praveen_2017
            wrote on 16 Sept 2017, 10:03 last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • M mostefa
              16 Sept 2017, 09:41

              @Praveen_2017 said in Time Edit field in QML:

              @mostefa Thanks it almost works but backspace is not working.
              For Example : If i enter 12:12:12 and try to clear the value using backspace then it's not working. My expectation is that it should become 00:00:00. Is there any way to achieve this ?

              Hi @Praveen_2017

              What if you match backspace for each digits in your expressions?

              You have to change your regExp on your validator to something like this:

              validator: RegExpValidator { regExp: /^([0-1\s]?[0-9\s]|2[0-3\s]):([0-5\s][0-9\s]):([0-5\s][0-9\s])$ / }
              
              P Offline
              P Offline
              pra7
              wrote on 16 Sept 2017, 10:10 last edited by
              #6

              @mostefa Thanks !!!it's working :-)

              O 1 Reply Last reply 19 Sept 2017, 11:07
              0
              • P pra7
                16 Sept 2017, 10:10

                @mostefa Thanks !!!it's working :-)

                O Offline
                O Offline
                ODБOï
                wrote on 19 Sept 2017, 11:07 last edited by
                #7

                @pra7 Go SOLVED

                P 1 Reply Last reply 19 Sept 2017, 13:35
                0
                • O ODБOï
                  19 Sept 2017, 11:07

                  @pra7 Go SOLVED

                  P Offline
                  P Offline
                  pra7
                  wrote on 19 Sept 2017, 13:35 last edited by
                  #8

                  @LeLev I didn't get ... Can you please explain ?

                  1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    ODБOï
                    wrote on 19 Sept 2017, 14:18 last edited by
                    #9

                    Im not regExp pro but this is working
                    TextField{
                    id:textEditTD
                    text : "00:00:00"
                    inputMask: "99:99:99"
                    inputMethodHints: Qt.ImhDigitsOnly
                    validator: RegExpValidator { regExp: /^([0-1\s]?[0-9\s]|2[0-3\s]):([0-5\s][0-9\s]):([0-5\s][0-9\s])$ / }

                              width:100
                              height:50
                          }
                    

                    LA

                    E 1 Reply Last reply 19 Sept 2017, 14:26
                    1
                    • O ODБOï
                      19 Sept 2017, 14:18

                      Im not regExp pro but this is working
                      TextField{
                      id:textEditTD
                      text : "00:00:00"
                      inputMask: "99:99:99"
                      inputMethodHints: Qt.ImhDigitsOnly
                      validator: RegExpValidator { regExp: /^([0-1\s]?[0-9\s]|2[0-3\s]):([0-5\s][0-9\s]):([0-5\s][0-9\s])$ / }

                                width:100
                                height:50
                            }
                      

                      LA

                      E Offline
                      E Offline
                      Eeli K
                      wrote on 19 Sept 2017, 14:26 last edited by
                      #10

                      @LeLev Maybe @pra7 meant "Go SOLVED"... which means marking a topic as solved so that others can see the original problem was solved in the thread. It's under "Topic Tools" menu for the one who has started the thread.

                      O 1 Reply Last reply 19 Sept 2017, 14:28
                      0
                      • E Eeli K
                        19 Sept 2017, 14:26

                        @LeLev Maybe @pra7 meant "Go SOLVED"... which means marking a topic as solved so that others can see the original problem was solved in the thread. It's under "Topic Tools" menu for the one who has started the thread.

                        O Offline
                        O Offline
                        ODБOï
                        wrote on 19 Sept 2017, 14:28 last edited by
                        #11

                        @Eeli-K this is @pra7 s topic not mine ^^

                        E 1 Reply Last reply 19 Sept 2017, 14:29
                        0
                        • O ODБOï
                          19 Sept 2017, 14:28

                          @Eeli-K this is @pra7 s topic not mine ^^

                          E Offline
                          E Offline
                          Eeli K
                          wrote on 19 Sept 2017, 14:29 last edited by
                          #12

                          @LeLev That's why I directed the rest of my comment to pra7 :)

                          O 1 Reply Last reply 19 Sept 2017, 14:32
                          0
                          • E Eeli K
                            19 Sept 2017, 14:29

                            @LeLev That's why I directed the rest of my comment to pra7 :)

                            O Offline
                            O Offline
                            ODБOï
                            wrote on 19 Sept 2017, 14:32 last edited by
                            #13

                            @Eeli-K sorry I have read your comment incorrectly :p

                            1 Reply Last reply
                            0

                            3/13

                            16 Sept 2017, 08:33

                            topic:navigator.unread, 10
                            • Login

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