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. [solved] QML TextInput with Time format hh:mm:ss

[solved] QML TextInput with Time format hh:mm:ss

Scheduled Pinned Locked Moved QML and Qt Quick
qmltexteditimhtime
2 Posts 2 Posters 5.1k 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.
  • H Offline
    H Offline
    HappyCoder
    wrote on 22 Apr 2015, 10:50 last edited by HappyCoder
    #1

    Hi,

    i need a user input with time format hh:mm:ss and did it this way below. But it is still
    possible to enter something like "12:90:11" and 90 minutes is not possible. The input
    should be checked for hours from 1 to 99 hours, minutes and seconds between 0 to 59.
    How can i do that?
    Thx
    Stefan
    PS: I don't know why <code> doesn't work?

    import QtQuick 2.4
    import QtQuick.Controls 1.3
    import QtQuick.Window 2.2
    import QtQuick.Layouts 1.1
    
    ApplicationWindow {
        title: qsTr("Hello World")
        width: 640
        height: 480
        visible: true
    
        property string currentintervall: "00:00:00"
    
        ColumnLayout {
            Text {
                id: li_userinput_text
                opacity: 1
                text: "User Interval: "
            }
            TextInput {
                opacity: 1
                id: li_userinput_edit
                // font.pointSize: 12
                inputMask: "00:00:00"
                cursorVisible: true
                inputMethodHints: Qt.ImhTime
                text: "00:00:00"
                onAccepted: currentintervall = li_userinput_edit.text
            }
            Text {
                text: "Current Interval: "
            }
            Text {
                height: 40
                //font.pointSize: 12
                width: parent.width
                text: currentintervall
            }
        }
    }
    

    Edited : Use ``` (3 backticks) instead - p3c0

    P 1 Reply Last reply 22 Apr 2015, 11:14
    0
    • H HappyCoder
      22 Apr 2015, 10:50

      Hi,

      i need a user input with time format hh:mm:ss and did it this way below. But it is still
      possible to enter something like "12:90:11" and 90 minutes is not possible. The input
      should be checked for hours from 1 to 99 hours, minutes and seconds between 0 to 59.
      How can i do that?
      Thx
      Stefan
      PS: I don't know why <code> doesn't work?

      import QtQuick 2.4
      import QtQuick.Controls 1.3
      import QtQuick.Window 2.2
      import QtQuick.Layouts 1.1
      
      ApplicationWindow {
          title: qsTr("Hello World")
          width: 640
          height: 480
          visible: true
      
          property string currentintervall: "00:00:00"
      
          ColumnLayout {
              Text {
                  id: li_userinput_text
                  opacity: 1
                  text: "User Interval: "
              }
              TextInput {
                  opacity: 1
                  id: li_userinput_edit
                  // font.pointSize: 12
                  inputMask: "00:00:00"
                  cursorVisible: true
                  inputMethodHints: Qt.ImhTime
                  text: "00:00:00"
                  onAccepted: currentintervall = li_userinput_edit.text
              }
              Text {
                  text: "Current Interval: "
              }
              Text {
                  height: 40
                  //font.pointSize: 12
                  width: parent.width
                  text: currentintervall
              }
          }
      }
      

      Edited : Use ``` (3 backticks) instead - p3c0

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 22 Apr 2015, 11:14 last edited by
      #2

      @HappyCoder Apart from using inputMask you will also need to set a validator. RegExpValidator would be perfect choice for it. A common validator for hh:mm:ss I found was this /^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$/
      Usage is simple:

      validator: RegExpValidator { regExp: /^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$/ }
      

      You can also find another validators.

      157

      1 Reply Last reply
      1

      2/2

      22 Apr 2015, 11:14

      • Login

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