QWizard and QWizardPage

  • Hi all

    I am making a wizard.

    My problem is that on the intro page the user selects one or more checkboxes. The next Wizardpages are determined of how many checkboxes the user checked

    ex the user checks three checkboxes then three Wizardpages should be added to the wizard, i.e my problem is how can I let the wizardPage add a page to the wizard. The wizard is dynamic and not static (linear non-linear) as in the examples given by Qt

    How woud I solve this ?


  • The options of the users are limited, so you could create all the QWizardPage that your QWizard may need to show and then just switch between them, based on what the user has chosen.

  • Hi Josue

    It is true that the options are limited. I found a solution but I don't know if its elegant here it is:

    @void IntroPage::CheckBoxClicked(bool checked) //SLOT for checkbox clicked(bool) SIGNAL
    QCheckBox box = (QCheckBox)sender();

    if(box->objectName() == "Monday")
        CheckBoxClickedHelper("Monday", "Monday sub", checked, box, this);
    else if(box->objectName() == "Tuesday")
        CheckBoxClickedHelper("Tuesday", "Tuesday sub", checked, box, this);


    void IntroPage::CheckBoxClickedHelper(const QString &title,
    const QString &subtitle,
    bool checked,
    QCheckBox *box,
    QWidget *parent)
    TrainingDay *day = new TrainingDay(title, subtitle, parent); //WizardPage
    int id = wizard->addPage(day); // TODO sort after weekday

        QAbstractButton *next = wizard->button(QWizard::NextButton);
        map.insert(box, id);


    It works I just thought there was an easier way...


  • Well, I've used QWizard only once, moment which I had to subclass QWizard and some of my QWizardPage too, mainly to get more control. I think an easy or more elegant way depends on what you want to do and how you judge your code. I recommend you to read all the "QWizard":http://qt-project.org/doc/qt-4.8/qwizard.html and "QWizardPage":http://qt-project.org/doc/qt-4.8/qwizardpage.html references to get a better idea about all the options you have.

    This example could help you too: http://qt-project.org/doc/qt-4.8/dialogs-licensewizard.html

  • I think the best way to go forward is to make your checkboxes available as fields in the wizard (read the documentation on those!). Then, subclass QWizard, and reimplement the nextId() function. That way, you can control which page is the next page. As you can access fields from the wizard as well, you can find access the values of the checkboxes from that function, and return the right value accordingly.

Log in to reply