[PyKDE] custom QValidator

Adam Tenderholt atenderholt at gmail.com
Wed Nov 22 20:33:45 GMT 2006


I'm trying to create a custom validator, but I'm not having any luck.
The class is reproduced below. When the custom validator is
initialized, it prints the debug message. However,the validate
function is never called. Any ideas?

This is PyQt-4.1 with Qt-4.2.1 (Mac/opensource), sip-4.5, and python 2.4.3.

Thanks,

Adam

------
class ElementValidator(QtGui.QValidator):
    def __init__(self, parent = None):
        QtGui.QValidator.__init__(self, parent)
        self.regexp = QtCore.QRegExp("[A-Z]")
        print "validator created"

    def validate(self, inputStr, pos):
        print "validating"
        if len(inputStr) > 2:
            return (QtGui.QValidator.Invalid,pos)

        if not self.regexp.exactMatch(inputStr[0]):
            return (QtGui.QValidator.Invalid,pos)

        try:
            table.element.index(inputStr)
        except ValueError:
            return (QtGui.QValidator.Intermediate,pos)
        else:
            return (QtGui.QValidator.Acceptable,pos)




More information about the PyQt mailing list