[PyQt] Bug in setEventFilter?

Brett Stottlemyer brett at stottlemyer.com
Sat Mar 19 01:44:06 GMT 2011


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?

Thanks,
Brett



More information about the PyQt mailing list