Results 1 to 5 of 5

Thread: Proper handling "Cancel" click for QWizard

  1. #1
    Join Date
    May 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question 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

  2. #2
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Proper handling "Cancel" click for QWizard

    Could this be what you are looking for?
    http://doc.trolltech.com/4.6/eventsandfilters.html

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default 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.

  4. #4
    Join Date
    Sep 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile 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).

    Qt Code:
    1. // install a handler for the cancel button
    2. disconnect( button( QWizard::CancelButton ), SIGNAL( clicked() ), this, SLOT( reject() ) );
    3. connect( button( QWizard::CancelButton ), SIGNAL( clicked() ), this, SLOT( cancelEvent() ) );
    To copy to clipboard, switch view to plain text mode 

    2) Implement your slot handling cancellation, e.g.:

    Qt Code:
    1. void SetupWizard::cancelEvent()
    2. {
    3. 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 ) {
    4. // allow cancel
    5. reject();
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2011, 19:21
  2. Replies: 1
    Last Post: 3rd May 2010, 09:25
  3. Qt4 eclipse integration : "action handling"
    By QiT in forum Qt-based Software
    Replies: 1
    Last Post: 24th July 2008, 10:20
  4. Replies: 3
    Last Post: 8th July 2008, 19:37
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.