input restricted lineEdit
-
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? -
@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?
-
@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?
-
@IknowQT
As the others have said, it would be much simpler to use the inbuiltQDoubleSpinBox
, 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 bysetInputMask()
and/orsetValidator()
. Have you tried those? -
-
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.
-
@IknowQT As @Christian-Ehrlicher told you you can remove the arrow buttons...
-
@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
-
@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 usingQRegularExpression
, why don't you heed that? I am not going to comment on what might or might not work withQRegExp
.