protected: bool eventFilter(QObject *obj, QEvent *event); bool frmPwd::eventFilter(QObject *obj, QEvent *event) { //如果用户按下了回车键,则触发修改密码信号 if (event->type()==QEvent::KeyPress) { QKeyEvent *keyEvent=static_cast<QKeyEvent *>(event); if (keyEvent->key()==Qt::Key_Return || keyEvent->key()==Qt::Key_Enter) { this->on_btnOk_clicked(); return true; } } return QObject::eventFilter(obj,event); }