QWizard Class
The QWizard class leads the user through a task in a sequence of pages. More…
| Header | #include <QWizard> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QDialog |
List of all members, including inherited members
Public Types
| enum | WizardButton |
| enum | WizardStyle |
| enum | WizardOption |
| typedef | WizardOptions |
Public Functions
| QWizard(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()) | |
| ~QWizard() | |
| int | addPage(QWizardPage *page) |
| void | setPage(int id, QWizardPage *page) |
| void | removePage(int id) |
| QWizardPage * | page(int id) const |
| bool | hasVisitedPage(int id) const |
| QList<int> | visitedIds() const |
| QList<int> | pageIds() const |
| void | setStartId(int id) |
| int | startId() const |
| QWizardPage * | currentPage() const |
| int | currentId() const |
| virtual bool | validateCurrentPage() |
| virtual int | nextId() const |
| void | setField(const QString &name, const QVariant &value) |
| QVariant | field(const QString &name) const |
| void | setWizardStyle(WizardStyle style) |
| WizardStyle | wizardStyle() const |
| void | setOption(WizardOption option, bool on = true) |
| bool | testOption(WizardOption option) const |
| void | setOptions(WizardOptions options) |
| WizardOptions | options() const |
| void | setButtonText(WizardButton which, const QString &text) |
| QString | buttonText(WizardButton which) const |
| void | setButton(WizardButton which, QAbstractButton *button) |
| QAbstractButton * | button(WizardButton which) const |
| void | setSideWidget(QWidget *widget) |
| QWidget * | sideWidget() const |
Reimplemented Public Functions
| void | setVisible(bool visible) |
Public Slots
| void | back() |
| void | next() |
| void | setCurrentId(int id) |
| void | restart() |
Signals
| void | currentIdChanged(int id) |
| void | helpRequested() |
| void | customButtonClicked(int which) |
| void | pageAdded(int id) |
| void | pageRemoved(int id) |
Protected Functions
| virtual void | initializePage(int id) |
| virtual void | cleanupPage(int id) |
Reimplemented Protected Functions
| void | done(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.
| Constant | Description |
|---|---|
QWizard::BackButton | Back. |
QWizard::NextButton | Next. |
QWizard::CommitButton | Commit, instead of Next on a commit page. |
QWizard::FinishButton | Finish. |
QWizard::CancelButton | Cancel. |
QWizard::HelpButton | Help, with HaveHelpButton. |
QWizard::CustomButton1 | A custom button, with HaveCustomButton1. |
QWizard::CustomButton2 | A custom button, with HaveCustomButton2. |
QWizard::CustomButton3 | A custom button, with HaveCustomButton3. |
QWizard::Stretch | Accepted for compatibility; there is no setButtonLayout(). |
QWizard::NoButton | No button. |
enum QWizard::WizardOption
Options of a wizard. WizardOptions is a typedef for QFlags<WizardOption>.
| Constant | Description |
|---|---|
QWizard::IndependentPages | Going back does not clean up the page, and a page is initialized only the first time. |
QWizard::IgnoreSubTitles | The subtitles are not shown. |
QWizard::ExtendedWatermarkPixmap | Accepted for compatibility; there are no pixmaps. |
QWizard::NoDefaultButton | Next and Finish are not default buttons. |
QWizard::NoBackButtonOnStartPage | No Back button on the first page. |
QWizard::NoBackButtonOnLastPage | No Back button on the last page. |
QWizard::DisabledBackButtonOnLastPage | A disabled Back button on the last page. |
QWizard::HaveNextButtonOnLastPage | A disabled Next button on the last page. |
QWizard::HaveFinishButtonOnEarlyPages | A Finish button on every page. |
QWizard::NoCancelButton | No Cancel button. |
QWizard::CancelButtonOnLeft | The Cancel button at the left. |
QWizard::HaveHelpButton | A Help button. |
QWizard::HelpButtonOnRight | The Help button at the right. |
QWizard::HaveCustomButton1 | The first custom button. |
QWizard::HaveCustomButton2 | The second custom button. |
QWizard::HaveCustomButton3 | The third custom button. |
QWizard::NoCancelButtonOnLastPage | No 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.
| Constant | Description |
|---|---|
QWizard::ClassicStyle | Classic. |
QWizard::ModernStyle | Modern. |
QWizard::MacStyle | macOS. |
QWizard::AeroStyle | Windows Aero. |
Member Function Documentation
QWizard::QWizard(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
Constructs a wizard with the given parent and window flags.
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().
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().
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.
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.
void QWizard::customButtonClicked(int which)
This signal is emitted when the user clicks a custom button; which is CustomButton1, CustomButton2 or CustomButton3.
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().
void QWizard::helpRequested()
This signal is emitted when the user clicks the Help button.
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().
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().
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.
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.
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().
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().
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().
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.
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.