[SOLVED] Closing QDialog with ESC
I have overridden
closeEvent´ in a QDialog-derived class and am able to captureclose´ events when, for instance, the user engages the cancel button. However, if the user hits ESC instead, `closeEvent´ isn't triggered and thus am unable to capture it and carry out needed processing.
It seems hitting ESC on a dialog invokes a different mechanism to `close´. How do I trap closing of dialogs via ESC?
It happens like this, because by hitting ESC you call reject slot on QDialog, and QDialog is only hidden. I think, that solution for this will be create a QShortcut in your QDialog-derived class with ESC sequence, and connect this shortcut's activated signal with dialog's close slot.
Hmm, I see now. Reject and the hide behaviour is key to understanding what's happening. Will investigate further and come up with a solution.
Thanks for the very helpful pointers!