Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to make lineEdit acceptable only integers?
Forum Update on Monday, May 27th 2025

How to make lineEdit acceptable only integers?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlineeditinputqtdesigner
7 Posts 5 Posters 31.7k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Welcome, how can I validate QLineEdit objects which could only accept int numbers? Objects are added via Qt designer tool.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You can use
      http://doc.qt.io/qt-5/qintvalidator.html#details

      1 Reply Last reply
      3
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        How about using a QSpinBox?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2
        • G Offline
          G Offline
          Gerd
          wrote on last edited by
          #4

          Hi,
          depending on your needs an input-mask may help. This can be set inside designer. Look for Input-mask in the Documentation of QLineEdit.

          Input Mask

          ? 1 Reply Last reply
          1
          • G Gerd

            Hi,
            depending on your needs an input-mask may help. This can be set inside designer. Look for Input-mask in the Documentation of QLineEdit.

            Input Mask

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @Gerd Could you give an simple example how to use this mask?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mostefa
              wrote on last edited by
              #6

              @testerius

              You can do something like this:

              ui->yourLineEdit->setValidator( new QIntValidator(yourMin(0 for example), yourMax(100 for example), this) );

              Here we have a qlineedit that will accept only integer from 0 to 100

              1 Reply Last reply
              1
              • G Offline
                G Offline
                Gerd
                wrote on last edited by
                #7

                Hi,

                for an integer input between 0 and 100 set the mask to "009". Thats all.

                1 Reply Last reply
                1

                • Login

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