PDA

View Full Version : how to overide key press event



maverick
30th May 2013, 08:06
need to override the keyPressEvent() and make my application to run on customized keys pressed

tried switch::cases and if conditions on Qt::keys but application is flowing through its own Qt::keyPressEvent();

also the connect(button1,SIGNAL(pressed()),this,SLOT(readFi le()));....
pressed() only takes space key from key board but not enter key

Please Help

rawfool
30th May 2013, 09:12
need to override the keyPressEvent()

// In .h file
protected:
void keyPressEvent(QKeyEvent* keyEvent)
{
// write your code here
}

maverick
30th May 2013, 09:34
i have already tried that but it is not being called.....

rockdemon
12th July 2013, 09:06
it only gets called for non special characters. Doesnt get called by tab key for instance.

If you create an event filter and grab keyboard in that component it works, but that's not always desired behaviour either?

rockdemon
12th July 2013, 15:55
i overcame the grab keyboard problem by grabbing it on show and releasing it on hide. ( This was needed because the tab keypresses in question were aimed at a class which inherited from QDialog it would seem....?)

pradeepreddyg95
12th July 2013, 17:36
use event filter ... on that object

Gokulnathvc
24th July 2013, 11:55
Try to use event filters, Key combinations . QKeyEvent and use Qt::AltModifier or event->key()==Qt::Key_L// Key_alphabets.