[PyKDE] trouble extending QValidate

Phil Thompson phil at river-bank.demon.co.uk
Fri Nov 30 18:41:46 GMT 2001


Erik Myllymaki wrote:
> 
> I am trying to extend QValidate. I want to make a date validator function
> eventually, but first I am just trying to make something simple work:
> 
> class QDateValidator(QValidator):
> 
>         def __init__(self,*args):
>                 apply(QValidator.__init__, (self,) + args)
> 
>         def validate(self,input,num):
>                 """
>                 what's num for ???
>                 """
>                 print input
>                 if (input == 'ppp'):
>                         return self.Acceptable
>                 elif(input =='pp' or input == 'p'):
>                         return self.Intermediate
>                 else:
>                         return self.Invalid
> 
> I get:
> 
>         TypeError: Invalid result type from QValidator.validate()
> 
> from ANY input.
> 
> I looked at the return type from the given validators, and it is a tuple:
> 
> (0,0) = Invalid
> (1,0) = Intermediate
> (2,0) = Acceptable
> 
> Yet the enums Invalid, Intermediate and Acceptable are 0,1,and 2 resp.
> 
> Any help appreciated.

num is the cursor position, with C++/Qt allows you to modify. This isn't
possible in Python so PyQt requires you to return a tuple of the state
and the (possibly modified) cursor position.

So your return statements should look like...

	return (self.Acceptable, num)

Phil




More information about the PyQt mailing list