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. How to enter only numbers in QML in TextField

How to enter only numbers in QML in TextField

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 4 Posters 12.6k 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.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on last edited by
    #1

    Hi!
    How in QML in TextField to make the ability to enter only numbers?

    T 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Since you only want to input numbers, wouldn't a SpinBox make more sense ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • IntruderExcluderI Offline
        IntruderExcluderI Offline
        IntruderExcluder
        wrote on last edited by
        #3

        Or look at inputMethodHints property.

        1 Reply Last reply
        5
        • M Mikeeeeee

          Hi!
          How in QML in TextField to make the ability to enter only numbers?

          T Offline
          T Offline
          Tom_H
          wrote on last edited by
          #4

          @mikeeeeee Use an IntValidator

          https://doc.qt.io/qt-5/qml-qtquick-intvalidator.html

                  TextField {
                      //...
                      validator: IntValidator {bottom: 1; top: 100}
                  }
          
          1 Reply Last reply
          5

          • Login

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