Proper handling "Cancel" click for QWizard
Hi,
I hoped that such question should be already asked but I can't find anything in search.
Question is simple - I wanna to catch "Cancel" click in my wizard to make sure that it was not accident (especially using Esc).
So I just want to show message box with question like "Are u sure?". But I can't find in documentation how to do it. There are some stuff for help button and 3 custom buttons but not for "cancel". Can someone guide me how to do it?
thanks in advance
Re: Proper handling "Cancel" click for QWizard
Re: Proper handling "Cancel" click for QWizard
I'm not sure if there is an option to do that in QWizard, but a solution I think works is this:
1. Set the wizard to not show a cancelbutton.
2. Create a custom cancel button
3. Use the customButtonClicked signal to ask if the user is sure.
Re: Proper handling "Cancel" click for QWizard
This is a little tricky, but easy.
1) In your wizard's constructor, disconnect the reject() slot from the clicked() signal of the cancel button and instead connect your own slot to handle the cancel button click (my slot is called cancelEvent() here).
Code:
// install a handler for the cancel button
disconnect( button( QWizard::CancelButton ), SIGNAL( clicked() ), this, SLOT( reject() ) );
connect( button( QWizard::CancelButton ), SIGNAL( clicked() ), this, SLOT( cancelEvent() ) );
2) Implement your slot handling cancellation, e.g.:
Code:
void SetupWizard::cancelEvent()
{
// allow cancel
reject();
}
}
Re: Proper handling "Cancel" click for QWizard
Create your own class that inherits from QWizard and define a method for reject. Both accept and reject are virtual.