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

List:       pykde
Subject:    Re: [PyKDE] trouble extending QValidate
From:       Phil Thompson <phil () river-bank ! demon ! co ! uk>
Date:       2001-11-30 18:41:46
[Download RAW message or body]

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


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

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