[PyKDE] custom QValidator

Adam Tenderholt atenderholt at gmail.com
Sat Nov 25 21:43:07 GMT 2006


Sorry about not including an example before. See the attached file.

Adam


On 11/25/06, Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
> On Wednesday 22 November 2006 8:33 pm, Adam Tenderholt wrote:
> > 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)
>
> A complete example would help...
>
> Attaching the validator to a QLineEdit didn't print "validating" but it did
> raise the expected exception about "table", ie. the method is being called.
>
> Phil
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: customdelegate2.py
Type: application/octet-stream
Size: 2400 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20061125/ee649a17/customdelegate2.obj


More information about the PyQt mailing list