0

enter image description here

I want to get input from user in an app that I code with pyqt5. The input I want to get must be either integer or float. So user shouldn't be able to enter anything else.

• If input is an integer, it must have a maximum 25 characters limit.

• If the input is a float, left of the dot must has maximum 25 characters limit, and the right of dot must has maximum 10 characters limit.

Methods I tried and didn't work :

  1. I added “Double Spin Box” and then i set maximum value to 9999999999999999999999999.9999999999. Then, when I type 9999999999999999999999999.9999999999 as an input and click on an empty place, the input I typed changes to another number.

  2. I added “Line Edit” and changed it “only integer mode” with this codes below:

from PyQt5.QtGui import QIntValidator
self.ui.lineEdit.setValidator(QIntValidator()) 

With the line edit I got, I can only get integer input. I can't get float input.

  1. I added “Line Edit” and i changed settings to 1000 character limit and only accepting integer input with the codes below:
rx = QtCore.QRegExp("[0-9]{1000}") 
val = QtGui.QRegExpValidator(rx)  
self.ui.LineEdit.setValidator(val) 

With the line edit I got, I can only get integer input. I can't get float input.

  1. I added spinbox but i couldnt change spinbox’s maximum character limit to 25. And i cant get float input with spinbox.
  • The [largest value that can be stored in a double](https://stackoverflow.com/q/1848700/984421) is 9007199254740992 (2^53). That's only 16 digits long, so a standard Qt/C++ int/double spin-box is no good. However, in PyQt you can easily [sub-class QAbstractSpinBox](https://stackoverflow.com/a/26861829/984421) to get the behaviour you want, since the Python int/float types aren't limited in that way. – ekhumoro Sep 11 '21 at 11:04

0 Answers0