6.0.0-rc4Source

QWizard Class

The QWizard class leads the user through a task in a sequence of pages. More…

Header#include <QWizard>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQDialog

List of all members, including inherited members

Public Types

Public Functions

QWizard(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
~QWizard()
intaddPage(QWizardPage *page)
voidsetPage(int id, QWizardPage *page)
voidremovePage(int id)
QWizardPage *page(int id) const
boolhasVisitedPage(int id) const
QList<int>visitedIds() const
QList<int>pageIds() const
voidsetStartId(int id)
intstartId() const
QWizardPage *currentPage() const
intcurrentId() const
virtual boolvalidateCurrentPage()
virtual intnextId() const
voidsetField(const QString &name, const QVariant &value)
QVariantfield(const QString &name) const
voidsetWizardStyle(WizardStyle style)
WizardStylewizardStyle() const
voidsetOption(WizardOption option, bool on = true)
booltestOption(WizardOption option) const
voidsetOptions(WizardOptions options)
WizardOptionsoptions() const
voidsetButtonText(WizardButton which, const QString &text)
QStringbuttonText(WizardButton which) const
voidsetButton(WizardButton which, QAbstractButton *button)
QAbstractButton *button(WizardButton which) const
voidsetSideWidget(QWidget *widget)
QWidget *sideWidget() const

Reimplemented Public Functions

voidsetVisible(bool visible)

Public Slots

voidback()
voidnext()
voidsetCurrentId(int id)
voidrestart()

Signals

voidcurrentIdChanged(int id)
voidhelpRequested()
voidcustomButtonClicked(int which)
voidpageAdded(int id)
voidpageRemoved(int id)

Protected Functions

virtual voidinitializePage(int id)
virtual voidcleanupPage(int id)

Reimplemented Protected Functions

voiddone(int result)

Detailed Description

A wizard shows one QWizardPage at a time, with a title, and buttons to go Back, to the Next page, to Finish, and to Cancel. Add the pages in order, or give them ids with setPage() and choose the next page in QWizardPage::nextId():

QWizard wizard(window);
wizard.setWindowTitle("New Project");
wizard.addPage(new IntroPage);
wizard.addPage(new DetailsPage);
if (wizard.exec() == QDialog::Accepted)
    create(wizard.field("name").toString());

Pages register fields: widgets whose value the wizard can read by name from any page. A mandatory field, whose name ends with "*", must be changed from its starting value before the user can go on.

The Next button is enabled when the current page is complete, and is replaced by Commit on a commit page, after which the user cannot go back. Finish shows on the last page.

See also QWizardPage and QDialog.

Differences from Qt

All the styles look the same: a title and a subtitle above the page, and the buttons in a row at the bottom. There are no pixmaps (setPixmap(), the watermark and the logo), no setButtonLayout(), no setTitleFormat() or setSubTitleFormat() (the text is plain), and no setDefaultProperty(). A field of a widget that Nt does not know needs its property; a changed signal given to registerField() is connected with the string-based syntax. The texts are not translated.

Member Type Documentation

enum QWizard::WizardButton

The buttons of a wizard.

ConstantDescription
QWizard::BackButtonBack.
QWizard::NextButtonNext.
QWizard::CommitButtonCommit, instead of Next on a commit page.
QWizard::FinishButtonFinish.
QWizard::CancelButtonCancel.
QWizard::HelpButtonHelp, with HaveHelpButton.
QWizard::CustomButton1A custom button, with HaveCustomButton1.
QWizard::CustomButton2A custom button, with HaveCustomButton2.
QWizard::CustomButton3A custom button, with HaveCustomButton3.
QWizard::StretchAccepted for compatibility; there is no setButtonLayout().
QWizard::NoButtonNo button.

enum QWizard::WizardOption

Options of a wizard. WizardOptions is a typedef for QFlags<WizardOption>.

ConstantDescription
QWizard::IndependentPagesGoing back does not clean up the page, and a page is initialized only the first time.
QWizard::IgnoreSubTitlesThe subtitles are not shown.
QWizard::ExtendedWatermarkPixmapAccepted for compatibility; there are no pixmaps.
QWizard::NoDefaultButtonNext and Finish are not default buttons.
QWizard::NoBackButtonOnStartPageNo Back button on the first page.
QWizard::NoBackButtonOnLastPageNo Back button on the last page.
QWizard::DisabledBackButtonOnLastPageA disabled Back button on the last page.
QWizard::HaveNextButtonOnLastPageA disabled Next button on the last page.
QWizard::HaveFinishButtonOnEarlyPagesA Finish button on every page.
QWizard::NoCancelButtonNo Cancel button.
QWizard::CancelButtonOnLeftThe Cancel button at the left.
QWizard::HaveHelpButtonA Help button.
QWizard::HelpButtonOnRightThe Help button at the right.
QWizard::HaveCustomButton1The first custom button.
QWizard::HaveCustomButton2The second custom button.
QWizard::HaveCustomButton3The third custom button.
QWizard::NoCancelButtonOnLastPageNo Cancel button on the last page.

typedef QWizard::WizardOptions

The WizardOptions type is a typedef for QFlags<WizardOption>. It stores an OR combination of WizardOption values.

enum QWizard::WizardStyle

The looks of a wizard; recorded only, all look the same in Nt.

ConstantDescription
QWizard::ClassicStyleClassic.
QWizard::ModernStyleModern.
QWizard::MacStylemacOS.
QWizard::AeroStyleWindows Aero.

Member Function Documentation

[explicit] QWizard::QWizard(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())

Constructs a wizard with the given parent and window flags.

[override] QWizard::~QWizard()

Destroys the wizard and its pages.

int QWizard::addPage(QWizardPage *page)

Adds page with an id one greater than the largest id so far, or 0 for the first page, and returns the id. The wizard takes the page as a child.

See also setPage().

[slot] void QWizard::back()

Goes back to the page before the current one. The current page is cleaned up, unless the IndependentPages option is set.

See also next().

QAbstractButton * QWizard::button(WizardButton which) const

Returns the button which, or nullptr.

See also setButton().

QString QWizard::buttonText(WizardButton which) const

Returns the text of the button which on the current page.

See also setButtonText().

[virtual, protected] void QWizard::cleanupPage(int id)

Is called when the user leaves the page with the given id with Back. The default implementation calls QWizardPage::cleanupPage().

int QWizard::currentId() const

Returns the id of the current page, or -1 before the wizard is shown.

[signal] void QWizard::currentIdChanged(int id)

This signal is emitted when the current page changes, with the id of the new one.

QWizardPage * QWizard::currentPage() const

Returns the current page, or nullptr before the wizard is shown.

[signal] void QWizard::customButtonClicked(int which)

This signal is emitted when the user clicks a custom button; which is CustomButton1, CustomButton2 or CustomButton3.

[override, protected] void QWizard::done(int result)

Reimplements QDialog::done().

Canceling resets the wizard to its first page for the next time; finishing checks the current page first.

QVariant QWizard::field(const QString &name) const

Returns the value of the field name of any page, or an invalid QVariant if there is no such field.

See also setField() and QWizardPage::registerField().

bool QWizard::hasVisitedPage(int id) const

Returns whether the user went through the page with the given id on the way to the current page.

See also visitedIds().

[signal] void QWizard::helpRequested()

This signal is emitted when the user clicks the Help button.

[virtual, protected] void QWizard::initializePage(int id)

Is called before the page with the given id is shown when the user goes to it. The default implementation calls QWizardPage::initializePage().

[slot] void QWizard::next()

Goes to the next page if the current page is valid. The next page is initialized first.

See also back() and validateCurrentPage().

[virtual] int QWizard::nextId() const

Returns the id of the page after the current one, or -1 if it is the last. The default implementation asks QWizardPage::nextId().

WizardOptions QWizard::options() const

Returns the options of the wizard; none by default.

QWizardPage * QWizard::page(int id) const

Returns the page with the given id, or nullptr.

[signal] void QWizard::pageAdded(int id)

This signal is emitted when a page is added, with its id.

QList<int> QWizard::pageIds() const

Returns the ids of the pages, in increasing order.

[signal] void QWizard::pageRemoved(int id)

This signal is emitted when a page is removed, with its id.

void QWizard::removePage(int id)

Removes the page with the given id, without deleting it. The page no longer has a parent.

See also page().

[slot] void QWizard::restart()

Goes back to the first page, cleaning up the visited pages, and initializes it.

void QWizard::setButton(WizardButton which, QAbstractButton *button)

Replaces the button which with button, or with a new push button if it is nullptr. The wizard takes the button as a child and deletes the one it had.

See also button().

void QWizard::setButtonText(WizardButton which, const QString &text)

Sets the text of the button which to text, for all the pages that do not set their own.

See also buttonText() and QWizardPage::setButtonText().

[slot] void QWizard::setCurrentId(int id)

Goes to the page with the given id by going forward with next() until it is reached, if it is ahead, or back if it was visited.

See also currentId().

void QWizard::setField(const QString &name, const QVariant &value)

Sets the field name of any page to value.

See also field().

void QWizard::setOption(WizardOption option, bool on = true)

Sets option if on is true, and clears it otherwise.

See also testOption().

void QWizard::setOptions(WizardOptions options)

Sets the options of the wizard to options.

See also options().

void QWizard::setPage(int id, QWizardPage *page)

Adds page with the given id. An id that is negative or taken is refused.

See also addPage() and removePage().

void QWizard::setSideWidget(QWidget *widget)

Puts widget at the left of the pages, such as a list of the steps, or removes it with nullptr. The wizard takes the widget as a child and deletes the one it had.

See also sideWidget().

void QWizard::setStartId(int id)

Makes the page with the given id the first page. By default it is the page with the smallest id.

See also startId().

[override] void QWizard::setVisible(bool visible)

Reimplements QDialog::setVisible().

Showing the wizard the first time goes to the first page.

void QWizard::setWizardStyle(WizardStyle style)

Sets the look of the wizard to style; recorded only.

QWidget * QWizard::sideWidget() const

Returns the widget at the left of the pages, or nullptr.

int QWizard::startId() const

Returns the id of the first page, or -1 if there are no pages.

See also setStartId().

bool QWizard::testOption(WizardOption option) const

Returns whether option is set.

[virtual] bool QWizard::validateCurrentPage()

Returns whether the user may leave the current page with Next, Commit or Finish. The default implementation asks QWizardPage::validatePage().

QList<int> QWizard::visitedIds() const

Returns the ids of the pages the user went through to the current page, in order, the current one included.

WizardStyle QWizard::wizardStyle() const

Returns the look of the wizard, ClassicStyle by default.