Important: Please read the Qt Code of Conduct -

[SOLVED] QDialog::closeEvent not fired by Esc-Key

  • Hello !
    I have subclassed the QDialog and need a preprocessing before a Window closes. It is a modal dialog. I found out that the QDialog::close() and the click on the window X Button fires the closeEvent.

    But pessing the Esc-Key does not fire the event.

    Why that ?

  • Moderators

    Hitting Esc is equivalent to calling reject().
    accept() and reject() call done() with appropriate error codes.
    Neither of these close() the window in the closeEvent sense, they merely hide() it.

    Pressing the "X" button calls close(). Calling close() generates a close event.

    As stated in the docs you should implement accept(), reject() or done() to do any custom closing behavior. closeEvent should only be used to store the dialog position if needed.

Log in to reply