[PyQt] Bug in setEventFilter?
Brett Stottlemyer
brett at stottlemyer.com
Tue Mar 22 03:26:32 GMT 2011
Phil,
Great support. Appears to work well.
Brett
-----Original Message-----
From: Phil Thompson [mailto:phil at riverbankcomputing.com]
Sent: Saturday, March 19, 2011 10:44 AM
To: Brett Stottlemyer
Cc: pyqt at riverbankcomputing.com
Subject: Re: [PyQt] Bug in setEventFilter?
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