Dmitriy
Dmitriy

Reputation: 5487

How to completely disable or hide Back button in QWizard?

I want to disable or hide Back button in QWizard dialog. How can I do it?

Upvotes: 6

Views: 5840

Answers (3)

PeterErnsthaft
PeterErnsthaft

Reputation: 395

An alternative (maybe more framework oriented) way would be to set the QWizardPage, which comes before the page you want the back button to be disabled in, to be a commit page. Just call this.setCommitPage(true) on a QWizardPage and the next page wont have its back button enabled.

from QWizardPage documentation

void QWizardPage::setCommitPage(bool commitPage) Sets this page to be a commit page if commitPage is true; otherwise, sets it to be a normal page. A commit page is a page that represents an action which cannot be undone by clicking Back or Cancel. A Commit button replaces the Next button on a commit page. Clicking this button simply calls QWizard::next() just like clicking Next does. A page entered directly from a commit page has its Back button disabled. See also isCommitPage().

If you want all the back buttons to be disabled, you could just call it on every page.

Upvotes: 6

Patrick Böker
Patrick Böker

Reputation: 3243

Calling

QWizard::button(QWizard::BackButton).hide()

in

QWizard::onCurrentIdChanged(int)

worked for me (in PyQt4).

This effectively hides the back button again on every wizard page, but it achieves the desired effect.

Upvotes: 5

Dmitriy
Dmitriy

Reputation: 5487

I've looked at Qt's sources and found out that it's possible to hide Back button by creating custom button layout and ommiting Back button in the list:

  QList<QWizard::WizardButton> button_layout;
  button_layout << QWizard::HelpButton << QWizard::Stretch <<
                   QWizard::NextButton << QWizard::CustomButton1 <<
                   QWizard::CancelButton;
  this->setButtonLayout(button_layout);

I hope this will save some time to somebody.

P.S.

AFAIU to avoid using QTimer it is needed to modify QWizard source code. The easies way will be to add a virtual function virtual void buttonsUpdated(); and call it from the end of QWizard's: void QWizardPrivate::_q_updateButtonStates() Then reimplement this buttonsUpdated() in your QWizard sublass and disable Back button there.

Upvotes: 7

Related Questions