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. input restricted lineEdit

input restricted lineEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 5 Posters 932 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1

    I made it possible to input only numbers in lineEdit. In the case of decimal point, it seems that there may be a case of entering a dot twice. I'm trying to add an exception for this, is there any way?

    I thought of a method to repeatedly check the dots as long as the length of the inputted character each time it is input.
    Is there any other good way?

    jsulmJ 1 Reply Last reply
    0
    • I IknowQT

      I made it possible to input only numbers in lineEdit. In the case of decimal point, it seems that there may be a case of entering a dot twice. I'm trying to add an exception for this, is there any way?

      I thought of a method to repeatedly check the dots as long as the length of the inputted character each time it is input.
      Is there any other good way?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @IknowQT Why don't you use https://doc.qt.io/qt-5/qspinbox.html and https://doc.qt.io/qt-5/qdoublespinbox.html if you want to enter numbers?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 1 Reply Last reply
      2
      • jsulmJ jsulm

        @IknowQT Why don't you use https://doc.qt.io/qt-5/qspinbox.html and https://doc.qt.io/qt-5/qdoublespinbox.html if you want to enter numbers?

        I Offline
        I Offline
        IknowQT
        wrote on last edited by
        #3

        @jsulm

        Not the ui I want. There should be no arrow buttons, and depending on the condition, QString and numbers should be inputable.

        Christian EhrlicherC 1 Reply Last reply
        0
        • I IknowQT

          @jsulm

          Not the ui I want. There should be no arrow buttons, and depending on the condition, QString and numbers should be inputable.

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @IknowQT said in input restricted lineEdit:

          There should be no arrow buttons,

          Maybe reading the documentation would help here. I know reading by yourself is hard but sometimes it really helps...

          QString and numbers should be inputable.

          QString? You mean non-digits? Why?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          I 1 Reply Last reply
          3
          • JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @IknowQT
            As the others have said, it would be much simpler to use the inbuilt QDoubleSpinBox, without arrows if you wish, as it already does everything for you --- both controlling input and accepting/returning a floating point number.

            If you insist on a QLineEdit, then input is controlled by setInputMask() and/or setValidator(). Have you tried those?

            I 1 Reply Last reply
            1
            • JonBJ JonB

              @IknowQT
              As the others have said, it would be much simpler to use the inbuilt QDoubleSpinBox, without arrows if you wish, as it already does everything for you --- both controlling input and accepting/returning a floating point number.

              If you insist on a QLineEdit, then input is controlled by setInputMask() and/or setValidator(). Have you tried those?

              I Offline
              I Offline
              IknowQT
              wrote on last edited by
              #6

              @JonB

              this->setValidator(new QRegExpValidator(QRegExp("[0-9.]*")));		// 실수
              

              I have already tried it and am using it.
              The problem is that you can enter the dot sign twice in a row.
              Please let me know if there is a way to limit the use of the .

              JonBJ 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @IknowQT said in input restricted lineEdit:

                There should be no arrow buttons,

                Maybe reading the documentation would help here. I know reading by yourself is hard but sometimes it really helps...

                QString and numbers should be inputable.

                QString? You mean non-digits? Why?

                I Offline
                I Offline
                IknowQT
                wrote on last edited by
                #7

                @Christian-Ehrlicher

                I am developing a program that uses a touchpad.
                It would be great if you use a spinbox, but the arrow buttons are too small to touch. The touchpad under development is small. Creating a separate arrow button takes up a lot of space because the screen is also small.

                If the program I'm developing uses a mouse, there are many different solutions. However, I have asked this question because the development environment is limited.

                jsulmJ 1 Reply Last reply
                0
                • I IknowQT

                  @Christian-Ehrlicher

                  I am developing a program that uses a touchpad.
                  It would be great if you use a spinbox, but the arrow buttons are too small to touch. The touchpad under development is small. Creating a separate arrow button takes up a lot of space because the screen is also small.

                  If the program I'm developing uses a mouse, there are many different solutions. However, I have asked this question because the development environment is limited.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by jsulm
                  #8

                  @IknowQT As @Christian-Ehrlicher told you you can remove the arrow buttons...

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  J.HilkJ 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @IknowQT As @Christian-Ehrlicher told you you can remove the arrow buttons...

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by J.Hilk
                    #9

                    @jsulm said in input restricted lineEdit:

                    @IknowQT As @Christian-Ehrlicher told you you can remove the arrow buttons...

                    I have to add, in case you don't know this @IknowQT . You can set a spinbox to be editable too . The center part is indeed a lineEdit


                    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
                    • I IknowQT

                      @JonB

                      this->setValidator(new QRegExpValidator(QRegExp("[0-9.]*")));		// 실수
                      

                      I have already tried it and am using it.
                      The problem is that you can enter the dot sign twice in a row.
                      Please let me know if there is a way to limit the use of the .

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #10

                      @IknowQT said in input restricted lineEdit:

                      The problem is that you can enter the dot sign twice in a row.

                      Well of course, since you allow any number of digits or dots!

                      There are plenty of examples of robust regular expressions for numeric input out there on the web. You could/should search for them to find which suits you. Here's one that caters for your single ., while also allowing no ., might be:

                      QRegularExpression("[0-9]*(\\.[0-9]*)?")
                      

                      And I have said to you umpteen times to stop using QRegExp and start using QRegularExpression, why don't you heed that? I am not going to comment on what might or might not work with QRegExp.

                      1 Reply Last reply
                      2

                      • Login

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