[PyQt] Bug in setEventFilter?

Phil Thompson phil at riverbankcomputing.com
Sat Mar 19 14:43:34 GMT 2011


On Sat, 19 Mar 2011 10:05:31 +0000, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> On Fri, 18 Mar 2011 21:44:06 -0400, "Brett Stottlemyer"
> <brett at stottlemyer.com> wrote:
>> I'm trying to process WM_INPUT in an application.  I know that in Qt
you
>> need to use QAbstractEventDispatcher and setEventFilter to get the
>> messages.
>> However, when I try to use setEventFilter, I get an Attribute error,
>> 'QAbstractEventDispatcher' object has no attribute 'setEventFilter'.
>> 
>> An example script is pretty simple and should allow the error to be
>> reproduced:
>> 
>> import sys
>> from PyQt4.QtCore import *
>> from PyQt4.QtGui import *
>> 
>> def myEventFilter(message):
>>     print message.message
>>     return True, id(message)
>>     
>> class QApp(QApplication):
>>     def __init__(self, *args):
>>         super(QApp, self).__init__(*args)
>>        
> QAbstractEventDispatcher.instance().setEventFilter(myEventFilter)
>>         
>> if __name__ == '__main__':
>>     app = QApp(sys.argv)
>>     widget = QPushButton("Push me")
>>     widget.show()
>>     sys.exit(app.exec_())
>> 
>> This is with Python 2.7 and PyQt 4.8.3 on a Win7 box.
>> 
>> Any suggestions?
> 
> It's not implemented because the message itself is platform specific and
> not part of Qt. That said there is partial support for XEvent to allow
you
> use the struct module to unpack it, so I could do something similar for
> NSEvent (MSG is already supported). That would probably be enough to
make
> setEventFilter() useful.
> 
> ...watch this space.

Support for setEventFilter() and filterEvent() will be in tonight's
snapshot. I confess that I haven't tried to build it on Windows (there is
some Windows specific code). Support is limited - you can only set a filter
for one dispatcher at a time.

Phil


More information about the PyQt mailing list