Nominate our 2022 Qt Champions!

[solved] ignore key press into editText?

  • how can I ignore key in key event in QTextEdit? if user pushs Enter key I want handle enter press event but I want to ignore new line into editText. how to do this?

    bool MyTextEdit::eventFilter(QObject *target, QEvent *event)
        if(event->type() == QKeyEvent::KeyPress){
            QKeyEvent *key = static_cast<QKeyEvent*>(event);
            if(key->key() == Qt::Key_Enter){
                qDebug() << "ok I can handle event here ";
                return true;
        return QObject::eventFilter(target, event);

  • I found solution. i remplemented keyPressEvent from QTextEdit class

    void MyTextEdit::keyPressEvent(QKeyEvent *e)
        if(e->key() == 16777220){
           //enter clicked
        return QTextEdit::keyPressEvent(e);