License Wizard Example

Screenshot of the License Wizard example

Most wizards have a linear structure, with page 1 followed by page 2 and so on until the last page. The Class Wizard example shows how to create such wizards.

Some wizards are more complex in that they allow different traversal paths based on the information provided by the user. The License Wizard example illustrates this. It provides five wizard pages; depending on which options are selected, the user can reach different pages.

The License Wizard pages

The example consists of the following classes:

  • LicenseWizard inherits QWizard and implements a non-linear five-page wizard that leads the user through the process of choosing a license agreement.

  • IntroPage, EvaluatePage, RegisterPage, DetailsPage, and ConclusionPage are QWizardPage subclasses that implement the wizard pages.

The LicenseWizard Class

The LicenseWizard class derives from QWizard and provides a five-page wizard that guides the user through the process of registering their copy of a fictitious software product. Here's the class definition:

 
Sélectionnez
class LicenseWizard : public QWizard
{
    Q_OBJECT

public:
    enum { Page_Intro, Page_Evaluate, Page_Register, Page_Details,
           Page_Conclusion };

    LicenseWizard(QWidget *parent = 0);

private slots:
    void showHelp();
};

The class's public API is limited to a constructor and an enum. The enum defines the IDs associated with the various pages:

Class name

Enum value

Page ID

IntroPage

Page_Intro

0

EvaluatePage

Page_Evaluate

1

RegisterPage

Page_Register

2

DetailsPage

Page_Details

3

ConclusionPage

Page_Conclusion

4

For this example, the IDs are arbitrary. The only constraints are that they must be unique and different from -1. IDs allow us to refer to pages.

 
Sélectionnez
LicenseWizard::LicenseWizard(QWidget *parent)
    : QWizard(parent)
{
    setPage(Page_Intro, new IntroPage);
    setPage(Page_Evaluate, new EvaluatePage);
    setPage(Page_Register, new RegisterPage);
    setPage(Page_Details, new DetailsPage);
    setPage(Page_Conclusion, new ConclusionPage);

    setStartId(Page_Intro);

In the constructor, we create the five pages, insert them into the wizard using QWizard::setPage(), and set Page_Intro to be the first page.

 
Sélectionnez
#ifndef Q_OS_MAC
    setWizardStyle(ModernStyle);
#endif

We set the style to ModernStyle on all platforms except macOS,

 
Sélectionnez