[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyKDE] custom QValidator
From:       "Adam Tenderholt" <atenderholt () gmail ! com>
Date:       2006-11-25 21:43:07
Message-ID: 7781a1b50611251343x322f6253u6284c9cbd4dee909 () mail ! gmail ! com
[Download RAW message or body]

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

Adam


On 11/25/06, Phil Thompson <phil@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
>

["customdelegate2.py" (application/octet-stream)]

_______________________________________________
PyKDE mailing list    PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic