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. TextFields with masks or validators seem unusable
Forum Updated to NodeBB v4.3 + New Features

TextFields with masks or validators seem unusable

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 4 Posters 1.1k Views 2 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.
  • StokestackS Offline
    StokestackS Offline
    Stokestack
    wrote on last edited by Stokestack
    #1

    Maybe I'm missing something: If you use a TextField's inputMask property or a validator, I don't see how you can use it; because the onEditingFinished signal never fires.

    Also, invalid text remains in the control when it loses focus. Because no signal fires at that point, your program can't even refresh the text.

    I have a TextField with a mask of "Nnnnnnnnn". It should require one alphanumeric character and allow up to eight more. But the user can enter all blanks (or nothing) and that's how the content stays after the control loses focus.

    So... how is this usable?

    J.HilkJ 1 Reply Last reply
    0
    • StokestackS Stokestack

      Maybe I'm missing something: If you use a TextField's inputMask property or a validator, I don't see how you can use it; because the onEditingFinished signal never fires.

      Also, invalid text remains in the control when it loses focus. Because no signal fires at that point, your program can't even refresh the text.

      I have a TextField with a mask of "Nnnnnnnnn". It should require one alphanumeric character and allow up to eight more. But the user can enter all blanks (or nothing) and that's how the content stays after the control loses focus.

      So... how is this usable?

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

      @Stokestack thats the point, you only get an editingFinished signal, when the user has entered a valid input, but there is no build in way to reset the text to its original value, when the input looses focus and an invalid input was made. You would have to store that value and reset it, when the TextField looses focus.

      you can somewhat restrict the user input, by setting an input mask and an input validator at the same time.


      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.

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

        @Stokestack thats the point, you only get an editingFinished signal, when the user has entered a valid input, but there is no build in way to reset the text to its original value, when the input looses focus and an invalid input was made. You would have to store that value and reset it, when the TextField looses focus.

        you can somewhat restrict the user input, by setting an input mask and an input validator at the same time.

        StokestackS Offline
        StokestackS Offline
        Stokestack
        wrote on last edited by Stokestack
        #3

        @J-Hilk said in TextFields with masks or validators seem unusable:

        you would have to store that value and reset it, when the TextField looses focus.

        But there's no (documented) signal to tell you when it loses focus. That's a big part of the problem.

        And what if the user presses Enter or Escape? Then they're "done editing," but the control presumably still has focus.

        J.HilkJ 1 Reply Last reply
        0
        • StokestackS Stokestack

          @J-Hilk said in TextFields with masks or validators seem unusable:

          you would have to store that value and reset it, when the TextField looses focus.

          But there's no (documented) signal to tell you when it loses focus. That's a big part of the problem.

          And what if the user presses Enter or Escape? Then they're "done editing," but the control presumably still has focus.

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

          @Stokestack said in TextFields with masks or validators seem unusable:

          But there's no (documented) signal to tell you when it loses focus. That's a big part of the problem.

          focus is a property it comes with the onFocusChanged signal....

          But, I totally agree, since there's an accepted signal, there should be a rejected signal as well, would make the world much easier


          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
          • fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by fcarney
            #5

            For one of our applications we have a Text Item that displays the value that is current. When the activeFocus is acquired by our TextInput we hide the Text Item and show the TextInput. When value is accepted we update the variable for the Text Item and hide the TextInput. This just happens to work for us. So we don't care if crap was in the TextInput as it won't affect the actual value if it is not accepted.

            C++ is a perfectly valid school of magic.

            GrecKoG 1 Reply Last reply
            0
            • fcarneyF fcarney

              For one of our applications we have a Text Item that displays the value that is current. When the activeFocus is acquired by our TextInput we hide the Text Item and show the TextInput. When value is accepted we update the variable for the Text Item and hide the TextInput. This just happens to work for us. So we don't care if crap was in the TextInput as it won't affect the actual value if it is not accepted.

              GrecKoG Offline
              GrecKoG Offline
              GrecKo
              Qt Champions 2018
              wrote on last edited by GrecKo
              #6

              @fcarney This can be done with a single TextField if I understand what you are saying:

              Column {
                  anchors.centerIn: parent
                  Label {
                      id: backend
                      text: "Initial Text"
                  }
                  TextField {
                      id: textField
                      Binding on text {
                          when: !textField.activeFocus
                          value: backend.text
                          restoreMode: Binding.RestoreNone
                      }
                      onAccepted: backend.text = text
                      Keys.onEscapePressed: textField.focus = false
              
                      onActiveFocusChanged: {
                          if (activeFocus)
                              selectAll();
                      }
                      background.visible: activeFocus
                      selectByMouse: true
                  }
              }
              

              I'm using something like this in one of our app, but by using readOnly instead of activeFocus and some buttons to change the readOnly state.

              Here is a video of it in action: https://streamable.com/h2aof5

              1 Reply Last reply
              2
              • StokestackS Offline
                StokestackS Offline
                Stokestack
                wrote on last edited by
                #7

                Thanks for the replies, guys. I'm pretty new to QML, so the binding example is very helpful.

                I still think these text controls desperately need improvement, though.

                1 Reply Last reply
                2

                • Login

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