PDA

View Full Version : Proper handling "Cancel" click for QWizard



Splinter
24th May 2010, 14:12
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

graciano
24th May 2010, 14:20
Could this be what you are looking for?
http://doc.trolltech.com/4.6/eventsandfilters.html

tbscope
24th May 2010, 14:20
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.

r.korthaus
17th September 2012, 14:25
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).



// 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.:



void SetupWizard::cancelEvent()
{
if( QMessageBox::question( this, trUtf8( "Quit Setup" ), trUtf8( "Setup is not complete yet. Are you sure you want to quit setup?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) {
// allow cancel
reject();
}
}

Lesiok
17th September 2012, 15:34
Create your own class that inherits from QWizard and define a method for reject. Both accept and reject are virtual.