Checking Qvalidator's State
First, sorry for my bad English. I'm trying to get an IP from user. I'm using QRegExpValidator for checking user input. The validator blocks unwanted characters succesfully. But I
Solution 1:
You're not doing the right thing here. The comparison:
validator.State==QtGui.QValidator.Intermediate
Compares an enumeration type to one of its values - this will always be False
!
Use the validate
method instead:
def addClientButtonClicked(self, edit, validator):
print("ip=", edit.text())
print(validator.validate(edit.text(), 0))
Then the result for 192.168.2.1
is:
('ip=', PyQt4.QtCore.QString(u'192.168.2.1'))
(2, 0)
The first element of the tuple returned by validate
is the state, which you can compare to the various states of QValidator
:
def addClientButtonClicked(self, edit, validator):
state, pos = validator.validate(edit.text(), 0)
print(state == QtGui.QValidator.Acceptable)
Prints True
for 192.168.2.1
Post a Comment for "Checking Qvalidator's State"