How to completely disable or hide Back button in QWizard?

落花浮王杯 提交于 2019-12-10 14:34:40

问题


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


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/9072626/how-to-completely-disable-or-hide-back-button-in-qwizard

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!