Jefer Bulan
Jefer Bulan

Reputation: 43

QLineEdit accepts only Integer

I already tried QIntvalidator and QRegExp but they are not working on my app. I don't know the problem.

This is my code in QIntvalidator:

self.lineEdit = QtWidgets.QLineEdit(self.page)
self.lineEdit.setValidator(QIntValidator())
self.lineEdit.setGeometry(QtCore.QRect(100, 10, 41, 20))
self.lineEdit.setInputMethodHints(QtCore.Qt.ImhDigitsOnly)
self.lineEdit.setMaxLength(4)
self.lineEdit.setObjectName("lineEdit")

#Int validator
int_validator = QtGui.QIntValidator()
self.lineEdit.setValidator(int_validator)

and this is the code that I tried the QRexExp:

reg_ex = QRegExp("[0-9]+.?[0-9]{,2}")
input_validator = QRegExpValidator(reg_ex, self.lineEdit)
self.lineEdit.setValidator(input_validator)

Upvotes: 1

Views: 97

Answers (0)

Related Questions