PDA

View Full Version : Custom QApplication and keypress



bibhukalyana
5th July 2014, 10: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
{
Q_OBJECT
public:
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 ?

thanks.

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

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

Cheers,
_

bibhukalyana
5th July 2014, 12: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 ?

anda_skoa
5th July 2014, 14: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.

Cheers,
_

bibhukalyana
5th July 2014, 15:50
Thanks.....:)

It is working fine.

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