class Q_EXPORT myLineEdit: public QLineEdit
在类中:
void myLineEdit::keyPressEvent(QKeyEvent *e)
{
switch(e->key())
{
case Key_Escape:
{
if (edited() && cursorPosition() > 0)
{
QKeyEvent ke(QEvent::KeyPress, Key_BackSpace, Key_BackSpace, 0);
QLineEdit::keyPressEvent( &ke );
}
else
{
QLineEdit::keyPressEvent( e );
}
break;
}
default:
QLineEdit::keyPressEvent( e );
}
}
bool myLineEdit::event( QEvent * e)
{
if ( e->type() == QEvent::KeyPress)
{
QKeyEvent* ke = (QKeyEvent*) e;
if(ke->key() == Key_Escape)
{
//ke->ingore();
ke->accept();
//return QWidget::event( e );
//return true;
}
}
return QLineEdit::event( e );
}
结果发现根本捕获不到Key_Escape, 一按程序就直接退出了,请问该如何做才能达到目标?
[ 此贴被wneunfn在2007-05-22 15:16重新编辑 ]