[SOLVED] QDialog how to catch all close events?
-
I have qDialog and on the @closeEvent(QCloseEvent *e) {}@ I can only catch if the user close the dialog from close button (x) only and not if the user cliched Ok or Cancel or hit the esc key. what event will do all this? I wist to emit a signal on the close event but reading the doc i've realised that the dialog will be hidden and not close on esc, Ok - accept(), or Cancel - reject(). hmm.. any good advise on how to catch all?
-
ok I've solved myself I do not know if this is the best option but here it is a work around or a solution :P
in dialog construct I have
@connect(this, SIGNAL(accepted()), this, SLOT(onCloseDialog()));
connect(this, SIGNAL(rejected()), this, SLOT(onCloseDialog()));
connect(this, SIGNAL(dialogIsClosing()), this, SLOT(onCloseDialog()));@and this
@void DialogName::closeEvent(QCloseEvent *event){
emit dialogIsClosing();
event->accept();
}@and then
@void DialogName::onCloseDialog{
//what ever you want on the form hide or closing or rejected or accepted
}@do not forget to add in the h file the emited signal for the close event.
-
If, when your dialog opens, you do this...
this->setAttribute(Qt::WA_DeleteOnClose);
...then it will be closed, not hidden on any close event, etc., and in the...
~Dialog()
...function, you can do some closing things and they will be reliably carried out.
-
If, when your dialog opens, you do this...
this->setAttribute(Qt::WA_DeleteOnClose);
...then it will be closed, not hidden on any close event, etc., and in the...
~Dialog()
...function, you can do some closing things and they will be reliably carried out.