Important: Please read the Qt Code of Conduct -

Press "Enter"

  • Hellow, i have some problem:
    I have a code:
    @ if (e->key()==Qt::Key_Enter)
    qDebug() << "1";
    emit makeIndent();
    It is doesnt work, but this code worke wright
    @ if (e->key()==Qt::Key_E)
    qDebug() << "1";
    emit makeIndent();
    I need that signal will called when user press key "Enter" to move to the next line

  • I guess the eventfilter for your widget or dialog intercepts the event to use it for something else. You should either make sure that you use a widget that will receive that event, or you should use an eventfilter yourself to get it before it is intercepted.

  • First, I think so too, but this code is first in the keyPressEvent:
    @void qssTextEdit::keyPressEvent(QKeyEvent *e)
    if (e->key()==Qt::Key_Enter)
    qDebug() << "1";
    emit makeIndent();
    //Next code
    And there are no any key filters in program. Code worke wright if instead "Enter" use Escape or Tab in example

  • eventfilter for your widget or dialog

    are you using a QDialog? Or which type of widget do you use?
    Enter is often caught for special actions, in dialog, e.g. to activate the default button.

  • I use QPlainTextEdit

  • Do you use the QPlainTextEdit within a QDialog? The QDialog catch the Enter key. So do you have to install a eventFilter.

  • I use QPlainTextEdit in the QMainWindow

  • Moderators

    Do you want Key_Enter or Key_Return?

    Key_Enter usually is the small enter key on the keypad.

  • In fact i use modified class from Custom Completer Example

  • Tobias Hunger, you are right
    Many thanks for all!!

Log in to reply