QDialog - closeEvent not triggered (bug?)
-
Hi,
I want to fire closeEvent on my custom QDialog, so I re-implemented it, It is triggered when I press the "X" close windows sign, but not when I press "ESC" on my keyboard, I thought ESC was supposed to do the same thing as pressing X in this context, am I wrong? I want to fire an event "are you sure you want to quit" and it needs to fire all the time when the windows is closed..
Thank you
-
Hi there,
I don't think it is a bug but a design decision. Pressing ESC causes the dialog to call the reject() function. The reject(), accept() and done() functions explicitly bypass the closeEvent().
From the "docs:":http://qt-project.org/doc/qt-4.8/qdialog.html#escape-key
bq. In order to modify your dialog's close behavior, you can reimplement the functions accept(), reject() or done(). The closeEvent() function should only be reimplemented to preserve the dialog's position or to override the standard close or reject behavior.
Hope it helps.
H. -
Thanks this helped, I was doing trial/error for the past 15minutes..
Fixed with this if you want ESC == Close window behavior
@void WorkoutDialog::reject() {
sureYouWantToQuit();
}void WorkoutDialog::closeEvent(QCloseEvent *event) {
sureYouWantToQuit();
}@