Search code examples
c++qtdialogescaping

Qt - Esc should not close the dialog


How to make Esc key to minimize a dialog? By default it closes. Should I process KeyEvent or there is a better way?


Solution

  • I think you may use this:

    void MyDialog::keyPressEvent(QKeyEvent *e) {
        if(e->key() != Qt::Key_Escape)
            QDialog::keyPressEvent(e);
        else {/* minimize */}
    }
    

    Also have a look at Events and Event Filters docs.