Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How to restrict a QSpinBox with following restrictions

    Mobile and Embedded
    4
    8
    682
    Loading More Posts
    • 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
      Sriu1 last edited by

      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.Hilk 1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        Hi
        You can use
        http://doc.qt.io/qt-5/qspinbox.html#validate
        to check if input is "legal"

        1 Reply Last reply Reply Quote 0
        • S
          Sriu1 last edited by

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

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @Sriu1 last edited by

            @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 Reply Quote 0
            • S
              Sriu1 last edited by

              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 Reply Quote 0
              • J.Hilk
                J.Hilk Moderators @Sriu1 last edited by

                @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

                Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply Reply Quote 0
                • S
                  Sriu1 last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by SGaist

                    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 Reply Quote 0
                    • First post
                      Last post