qtkey-bindingsqdialognon-modal

Escape in QDialog works only in modal mode?


Esc does not work for my dialog in non-modal mode, event going to underlying window. Only adding

setWindowModality(Qt::WindowModal);

to the dialog on creation makes the Esc key work and calls the reject() slot. Is it normal or possible to Esc in/from non-modal dialog?


Solution

  • Changed

    dialog->show();
    

    call to

    // Shows the dialog as a modal dialog, blocking until the user closes it.
    dialog->exec();
    

    Works fine for now. Seems the only way to catch event in the dialog, non-modal does not allow this or use key event filter as mentioned in another answer.