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. How to restrict a QSpinBox with following restrictions

How to restrict a QSpinBox with following restrictions

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
8 Posts 4 Posters 1.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.
  • S Offline
    S Offline
    Sriu1
    wrote on last edited by
    #1
    1. It should not take 01,002.. It should take 0 or 1 or 2 i.e 0 should not be prefixed with natural numbers.
    2. It should not take 00000000000000000000000000000000
    J.HilkJ 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/qspinbox.html#validate
      to check if input is "legal"

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sriu1
        wrote on last edited by
        #3

        Can you send a snippet please.The document is hard to understand

        mrjjM 1 Reply Last reply
        0
        • S Sriu1

          Can you send a snippet please.The document is hard to understand

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Sriu1

          Hi, its protected so you will need to subclass for it.
          Maybe others have better idea/easier.

          Did you try with valueChanged() signal ?

          It accepts ints and 001 is also valid int, so it might be a bit hard to get rid of.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sriu1
            wrote on last edited by
            #5

            Hi @mrjj
            In designer mode I have a QSpinBox when I call mainwindow.show() and enter value in QSpinBox it should not take

            1. 000000000000000
              and
            2. 01,002,.. It should take 0,1,2
              Can you suggest?
            1 Reply Last reply
            0
            • S Sriu1
              1. It should not take 01,002.. It should take 0 or 1 or 2 i.e 0 should not be prefixed with natural numbers.
              2. It should not take 00000000000000000000000000000000
              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @Sriu1 a 0 is only valid as a intermetiate state, as soon as you press return or the QSpinbox looses focus, the display inside the QSpinbox should correct itself to a number bewteen 1-9 before the comma or a 0 if its the only digit


              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
              • S Offline
                S Offline
                Sriu1
                wrote on last edited by
                #7

                @J-Hilk Is there any way to restrict the user from not entering 00000000000000000000000.

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

                  Hi,

                  What is the problem with you users entering such a big number of zeros ?

                  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
                  0

                  • Login

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