Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Numeric virtual keyboard for QML TextInput
Forum Updated to NodeBB v4.3 + New Features

Numeric virtual keyboard for QML TextInput

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 3 Posters 9.1k Views 1 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.
  • D Offline
    D Offline
    deion
    wrote on last edited by
    #1

    Hi all,
    I have a QML TextInput element that should hold a TCP port number, so the user should only enter numbers in that TextInput; Therefore I would like the virtual keyboard that opens when clicking on the TextInput to contain only digits (you know, like the numeric virtual keyboard on iPhone). I tried adding this (just like in the documentation):
    @ TextInput{
    validator: IntValidator{bottom: 11; top: 31;}
    focus: true
    }
    @
    However the virtual keyboard that opens is qwerty keyboard, I am able to input literal characters because auto-correction is enabled (btw does anyone know how to disable autocorrection??), but when pressing the return key or accepting the autocorrection suggestion the TextInput text disappears, because the text entered was not a number between 11 and 31 like in the code above. However this is so confusing for the end user ! It would be so MUCH SIMPLER if the virtual keyboard would have only digits.

    How can I do this? (Again this is so easy on iPhone..., both as a user and a programmer, no offense).

    1 Reply Last reply
    0
    • AlicemirrorA Offline
      AlicemirrorA Offline
      Alicemirror
      wrote on last edited by
      #2

      I think that what you do is correct. As a matter of fact the validator should check what you input in the field while the focus opens the keyboard. It has no matter that the keyboard is opened in one configuration or another. This is with this code a user decision. Simply if the user try to insert and alphanumeric character it is not accepet because the validator.

      What should be seen is if there is a way to filter the focus action: when the object gain focus you should intercept this event and do what you need - if possible - i.e. showing the keyboard in the numeric mode instead of the standard VKB mode.
      As you can see in this "focus documentation":http://developer.qt.nokia.com/doc/qt-4.7/qdeclarativefocus.html controls on the key pressed are done on the text input object content. This means that the user should have pressed something. I have not found anything related to a specific keyboard setting in some condition.

      Anyway there are some projects in developer.nokia.com that manages custom keyboards. I think this maybe somehting that help you in this problem.

      Enrico Miglino (aka Alicemirror)
      Balearic Dynamics
      Islas Baleares, Ibiza (Spain)
      www.balearicdynamics.com

      1 Reply Last reply
      0
      • E Offline
        E Offline
        echemus
        wrote on last edited by
        #3

        There is a simpler solution, if you add the "inputMethodHints" property you can select what type of input you wish to have for the TextInput eg:

        inputMethodHints: Qt.ImhFormattedNumbersOnly

        There are a variety of hints that can be used, the documentation for QML doesn't really explain that these are usable. You have to look at the "C++ documentation":http://apidocs.meego.com/1.2/qt4/qt.html#InputMethodHint-enum to find out what is available.

        Remember to substitute the namespace operator "::" with '.' to use the values with QML.

        1 Reply Last reply
        0

        • Login

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