[PyKDE] Next attempt to tackle QSpinBox strangeness

Hans-Peter Jansen hpj at urpla.net
Fri Jan 24 14:45:01 GMT 2003


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.

> 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.

TIA,
Pete
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sbtest.py
Type: text/x-python
Size: 4409 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20030124/9e0917e0/sbtest.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sbtest.cpp
Type: text/x-c++src
Size: 4653 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20030124/9e0917e0/sbtest.bin
-------------- next part --------------
######################################################################
# Automatically generated by qmake (1.03a) Fri Jan 24 12:40:01 2003
######################################################################

TEMPLATE = app
CONFIG -= moc
CONFIG += qt warn_on thread

# Input
SOURCES += sbtest.cpp


More information about the PyQt mailing list