Reputation: 73
I've created a wizard by subclassing QWizard, and I created pages of my wizard by subclassing QWizardPage.
I would like to show a confirmation dialog when the user press the Back button, and I want my wizard to not go to the previous page if the user press no on the confirmation dialog.
When clicking Next on a QWizard dialog, the virtual function bool validatePage()
is called and allows to return false if we don't want to go to the next page (for example when there is an incomplete field).
However, when pressing Back, I don't know any way to say "Don't go back". The virtual function void cleanupPage()
is called (I can ask the user confirmation here), but the Wizard will go back anyway.
Is it possible to do so?
Thanks in advance.
Upvotes: 2
Views: 1038
Reputation: 73
I finally achieve what I wanted (not sure this is the best way...) by disconnecting the back button signal, and connecting it to my custom slot.
MyWizard::MyWizard(QWidget *parent) : QWizard(parent)
{
// [...]
connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(onPageChanged(int)));
}
void MyWizard::onPageChanged(int id)
{
disconnect(button(BackButton), SIGNAL(clicked(bool)), 0, 0);
connect(button(BackButton), SIGNAL(clicked(bool)), this, SLOT(onBackButtonClicked()));
}
void MyWizard::onBackButtonClicked()
{
if (currentId() > Page_Intro && !confirmation(tr("Are you sure you want to go back?")))
return;
back();
}
Note that if you do the connection/disconnection on the Wizard constructor, it does not work (Qt connect it when you pass the first page).
Upvotes: 3
Reputation: 181
Try to do it with void QWizardPage::setCommitPage(bool commitPage) function. This function prevents user to going back on the page. Set it on cleanupPage() of the wizard:
MyWizard::cleaupPage(int id)
{
//Test here if 'id' is the page that you want and the do the following
if(QMessageBox::question(...) == QMessageBox::Yes)
this->page(id)->setCommitPage(false);
else
this->page(id)->setCommitPage(true);
}
Upvotes: 0