PDA

View Full Version : issues regarding how to reimplement keyPressEvent()



Askar
14th December 2009, 14:13
Dear Friends,
I need to override the Esc key event so i tried to reimplement keyPressEvent() of QDialog. but it is not executed when i pressed any key. the code is given below.

void Myclass::keyPressEvent(QKeyEvent *e)
{
if(e->key()==Qt::Key_Escape)
{
QMessageBox(0,"Error","Key press");
}
else
{
QDialog::keyPressEvent(e);
}
}


while defining QDialog i gave setFocusPolicy(Qt::StrongFocus) as like below

win = new QDialog(this);
QDialog::setFocusPolicy(Qt::StrongFocus);

can any body help me where im getting wrong

high_flyer
14th December 2009, 14:32
the key event is being received by another widget in your dialog which has input focus.
You should install an evenFilter for that widget in your dialog and there trap the QKeyEvent.