[PyKDE] Next attempt to tackle QSpinBox strangeness

Phil Thompson phil at river-bank.demon.co.uk
Sat Jan 25 17:03:00 GMT 2003


On Friday 24 January 2003 1:43 pm, Hans-Peter Jansen wrote:
> On Thursday 23 January 2003 19:46, me wrote:
> > Problem: reimplemented QSpinBox don't get focus events and doesn't behave
> > correctly on up/down cursor key events (value doesn't change).
>
> Also, manually editing the QSpinBox value doesn't generate a valueChanged
> signal, nor does it revert invalid values.
>
> > Therefore, I'm going to translate this app to c++ in order
> > to check this behaviour of Qt directly soon.
>
> Done, attached. Looks like the c++ version doesn't generate focus events,
> either, but behaves correctly on cursor keys and manual editing.
> Consequently both actions generate a valueChanged signal, unlike the py
> version.

Thanks for putting the effort into this - it was very helpful. The bug is that 
qspinbox.sip should say...

bool eventFilter(QObject *,QEvent *);

...instead of...

void eventFilter(QObject *,QEvent *);

It will be fixed in tonight's snapshot.

> > Interesting side note: I needed to prepare the event() handlers not to
> > call the base class in order to avoid an attribute error during
> > qApp.quit(). Phil, it appears, that the QSpinBox base class disappears
> > while subclassed SpinBox event() handler is active. This doesn't look
> > right to me.
>
> While making both versions functional identical, I've rewritten the event
> decoder qEvent(), but couldn't believe my eyes: during qApp.quit() the
> value of the global defined qEventDict{} in the .py script is replaced
> with a None value somewhere under the covers! Please remove the try/except
> statement in qEvent, uncomment the print statement and look yourself:
>
> close app
> PushButton event: <type 'NoneType'>
> Traceback (most recent call last):
>   File "sbtest.py", line 121, in event
>     print "PushButton event:", qEvent(t)
>   File "sbtest.py", line 79, in qEvent
>     if t in qEventDict.keys():
> AttributeError: 'NoneType' object has no attribute 'keys'
> SpinBox event: <type 'NoneType'>
> Traceback (most recent call last):
>   File "sbtest.py", line 96, in event
>     print "SpinBox event:", qEvent(t)
>   File "sbtest.py", line 79, in qEvent
>     if t in qEventDict.keys():
>
> Something is definitely going wrong here.

I think this is just Python and Qt racing each other to tidy up. As the 
behaviour of either isn't formally documented I think it's more a feature 
rather than a bug.

Phil




More information about the PyQt mailing list