View Full Version : Custom QApplication and keypress

5th July 2014, 11:24
Hi everyone,
I want to detect key press and mouse event from any widget. So I inherit QApplication and re implement the notify function.
I am able to detect mouse and key press event from any widget. But in some widget key press is not working fine. In lineEdit texts are not able to print escape key is not working in some widget.....

But if i remove the implementation of notify the all things are fine.

class MyApplication : public QApplication
MyApplication(int argc ,char** argv);

bool notify(QObject *obj, QEvent *e);


bool MyApplication::notify(QObject *obj, QEvent *e)
return obj->event(e);

Can anybody please tell me what is the problem ?


5th July 2014, 12:40
You don't have to subclass for that.

You can install an event filter on the QApplication instance.
See QObject::eventFilter().


5th July 2014, 13:59
Thanks for reply.
I have a doubt. I am using a stack widget. In which widget i will re implement the eventFilter ?

I re implemented the eventFilter in a widget but nothing happened for key press and mouse click.

Can you please tell me little bit more ?

5th July 2014, 15:55
You don't have to implement the event filter in any widget, a normal QObject subclass will do.
You then install an instance of that class on the QApplication instance as its event filter.


5th July 2014, 16:50

It is working fine.

QApplication::installEventFilter(QObject*) did the work for me.