[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 ";
                event->ignore();
                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;
        }
    
        return QTextEdit::keyPressEvent(e);
    }
    
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.