qtqwizardqwizardpage

How to use CustomButton to change QWizard page in Qt?


I have a QWizard with 2 custom buttons (on top of the Back\Next buttons).

I wish that a click on my custom button will change to another QWizardPage.

How do I do that? Thanks


Solution

  • That would be doable by connecting the custom buttons clicked signal with a slot which handles moving to next page.

    QWizard wizard;
    
    wizard.setButtonText(QWizard::CustomButton1, "Custom button");
    wizard.setOption(QWizard::HaveCustomButton1, true);
    
    QObject::connect(&wizard, &QWizard::customButtonClicked, [&]
    {
        wizard.next();
    });
    

    The code above would create a wizard with a custom button which would function like the default "next" button. If you want to create a dynamic (as opposed to linear wizard which it is by default) you would need to reimplement QWizard::nextId(). Please see:

    https://doc.qt.io/qt-5/qwizard.html#nextId