Hi all,

I have a simple QWizard (code below). When the user moves to page 2 of the wizard a longish, asynchronous network request is made. During that request I'd like to disable the Back (and potentially other) buttons on the wizard. When the request is complete the buttons will be enabled and going Back is allowed. Using setEnabled() on the back button is not working, presumably the QWizard code is re-enabling it. I have had to resort to disabling the entire wizard.

I know that I could set page 1 as a commit page, but that would prohibit the back button entirely on page 2. I only need a temporary block on the back button.

Have I missed the really obvious way to do this?

Cheers,
Chris

Qt Code:
  1. #include <QtGui>
  2. #include <QDebug>
  3.  
  4. class Page1: public QWizardPage {
  5. Q_OBJECT
  6.  
  7. QLabel *label;
  8. public:
  9. Page1(QWidget *p = 0): QWizardPage(p) {
  10. label = new QLabel(tr("This is an example page 1"), this);
  11. label->setWordWrap(true);
  12.  
  13. QVBoxLayout *layout = new QVBoxLayout;
  14. layout->addWidget(label);
  15. setLayout(layout);
  16. }
  17. };
  18.  
  19. class Page2: public QWizardPage {
  20. Q_OBJECT
  21.  
  22. QLabel *label;
  23. public:
  24. Page2(QWidget *p = 0): QWizardPage(p) {
  25. label = new QLabel(tr("This is an example page 2"), this);
  26. label->setWordWrap(true);
  27.  
  28. QVBoxLayout *layout = new QVBoxLayout;
  29. layout->addWidget(label);
  30. setLayout(layout);
  31. }
  32. void initializePage() {
  33. // This does not disable the button for the long process
  34. wizard()->button(QWizard::BackButton)->setEnabled(false);
  35. // so I have to resort to this
  36. // wizard()->setEnabled(false);
  37.  
  38. label->setText("Starting");
  39. // simulate a longish process
  40. QTimer::singleShot(5000, this, SLOT(expired()));
  41. }
  42. public slots:
  43. void expired() {
  44. label->setText("Finished");
  45. wizard()->button(QWizard::BackButton)->setEnabled(true);
  46. // wizard()->setEnabled(true);
  47. }
  48. };
  49.  
  50. class Wizard : public QWizard {
  51. Q_OBJECT
  52. public:
  53. Wizard(QWidget *p = 0) : QWizard(p) {
  54. addPage(new Page1);
  55. addPage(new Page2);
  56. }
  57.  
  58. };
  59.  
  60.  
  61. int main(int argc, char *argv[])
  62. {
  63. QApplication app(argc, argv);
  64.  
  65.  
  66. Wizard wiz;
  67. wiz.show();
  68. return app.exec();
  69. }
  70. #include "main.moc"
To copy to clipboard, switch view to plain text mode