QWizard 类

The QWizard class provides a framework for wizards. 更多...

头: #include <QWizard>
qmake: QT += widgets
Since: Qt 4.3
继承: QDialog

公共类型

enum WizardButton { BackButton, NextButton, CommitButton, FinishButton, ..., Stretch }
enum WizardOption { IndependentPages, IgnoreSubTitles, ExtendedWatermarkPixmap, NoDefaultButton, ..., NoCancelButtonOnLastPage }
flags WizardOptions
enum WizardPixmap { WatermarkPixmap, LogoPixmap, BannerPixmap, BackgroundPixmap }
enum WizardStyle { ClassicStyle, ModernStyle, MacStyle, AeroStyle }

特性

公共函数

QWizard (QWidget * parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags())
~QWizard ()
int addPage (QWizardPage * page )
QAbstractButton * button (WizardButton which ) const
QString buttonText (WizardButton which ) const
int currentId () const
QWizardPage * currentPage () const
QVariant field (const QString & name ) const
bool hasVisitedPage (int id ) const
virtual int nextId () const
WizardOptions options () const
QWizardPage * page (int id ) const
QList<int> pageIds () const
QPixmap pixmap (WizardPixmap which ) const
void removePage (int id )
void setButton (WizardButton which , QAbstractButton * button )
void setButtonLayout (const QList<WizardButton> & layout )
void setButtonText (WizardButton which , const QString & text )
void setDefaultProperty (const char * className , const char * property , const char * changedSignal )
void setField (const QString & name , const QVariant & value )
void setOption (WizardOption option , bool on = true)
void setOptions (WizardOptions options )
void setPage (int id , QWizardPage * page )
void setPixmap (WizardPixmap which , const QPixmap & pixmap )
void setSideWidget (QWidget * widget )
void setStartId (int id )
void setSubTitleFormat (Qt::TextFormat format )
void setTitleFormat (Qt::TextFormat format )
void setWizardStyle (WizardStyle style )
QWidget * sideWidget () const
int startId () const
Qt::TextFormat subTitleFormat () const
bool testOption (WizardOption option ) const
Qt::TextFormat titleFormat () const
virtual bool validateCurrentPage ()
QList<int> visitedPages () const
WizardStyle wizardStyle () const

重实现公共函数

virtual void setVisible (bool visible )
virtual QSize sizeHint () const

公共槽

void back ()
void next ()
void restart ()

信号

void currentIdChanged (int id )
void customButtonClicked (int which )
void helpRequested ()
void pageAdded (int id )
void pageRemoved (int id )

保护函数

virtual void cleanupPage (int id )
virtual void initializePage (int id )

重实现保护函数

virtual void done (int result )
virtual bool event (QEvent * event )
virtual bool nativeEvent (const QByteArray & eventType , void * message , long * result )
virtual void paintEvent (QPaintEvent * event )
virtual void resizeEvent (QResizeEvent * event )

额外继承成员

详细描述

The QWizard class provides a framework for wizards.

A wizard (also called an assistant on macOS) is a special type of input dialog that consists of a sequence of pages. A wizard's purpose is to guide the user through a process step by step. Wizards are useful for complex or infrequent tasks that users may find difficult to learn.

QWizard 继承 QDialog and represents a wizard. Each page is a QWizardPage (a QWidget subclass). To create your own wizards, you can use these classes directly, or you can subclass them for more control.

话题:

通俗范例

The following example illustrates how to create wizard pages and add them to a wizard. For more advanced examples, see Class Wizard and License Wizard .

QWizardPage *createIntroPage()
{
    QWizardPage *page = new QWizardPage;
    page->setTitle("Introduction");
    QLabel *label = new QLabel("This wizard will help you register your copy "
                               "of Super Product Two.");
    label->setWordWrap(true);
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(label);
    page->setLayout(layout);
    return page;
}
QWizardPage *createRegistrationPage()
{
    ...
}
QWizardPage *createConclusionPage()
{
    ...
}
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
#ifndef QT_NO_TRANSLATION
    QString translatorFileName = QLatin1String("qt_");
    translatorFileName += QLocale::system().name();
    QTranslator *translator = new QTranslator(&app);
    if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
        app.installTranslator(translator);
#endif
    QWizard wizard;
    wizard.addPage(createIntroPage());
    wizard.addPage(createRegistrationPage());
    wizard.addPage(createConclusionPage());
    wizard.setWindowTitle("Trivial Wizard");
    wizard.show();
    return app.exec();
}
					

向导外观和感觉

QWizard supports four wizard looks:

You can explicitly set the look to use using setWizardStyle () (e.g., if you want the same look on all platforms).

ClassicStyle ModernStyle MacStyle AeroStyle

注意: AeroStyle has effect only on a Windows Vista system with alpha compositing enabled. ModernStyle is used as a fallback when this condition is not met.

In addition to the wizard style, there are several options that control the look and feel of the wizard. These can be set using setOption () 或 setOptions (). For example, HaveHelpButton makes QWizard show a 帮助 button along with the other wizard buttons.

You can even change the order of the wizard buttons to any arbitrary order using setButtonLayout (), and you can add up to three custom buttons (e.g., a 打印 button) to the button row. This is achieved by calling setButton () 或 setButtonText () 采用 CustomButton1 , CustomButton2 ,或 CustomButton3 to set up the button, and by enabling the HaveCustomButton1 , HaveCustomButton2 ,或 HaveCustomButton3 options. Whenever the user clicks a custom button, customButtonClicked () is emitted. For example:

        wizard()->setButtonText(QWizard::CustomButton1, tr("&Print"));
        wizard()->setOption(QWizard::HaveCustomButton1, true);
        connect(wizard(), &QWizard::customButtonClicked,
                this, &ConclusionPage::printButtonClicked);
					

向导页面的元素

Wizards consist of a sequence of QWizardPage s. At any time, only one page is shown. A page has the following attributes:

The diagram belows shows how QWizard renders these attributes, assuming they are all present and ModernStyle is used:

subTitle 有设置, QWizard displays it in a header, in which case it also uses the BannerPixmap LogoPixmap to decorate the header. The WatermarkPixmap is displayed on the left side, below the header. At the bottom, there is a row of buttons allowing the user to navigate through the pages.

The page itself (the QWizardPage widget) occupies the area between the header, the watermark, and the button row. Typically, the page is a QWizardPage on which a QGridLayout is installed, with standard child widgets ( QLabel s, QLineEdit s, etc.).

If the wizard's style is MacStyle , the page looks radically different:

The watermark, banner, and logo pixmaps are ignored by the MacStyle 。若 BackgroundPixmap is set, it is used as the background for the wizard; otherwise, a default "assistant" image is used.

The title and subtitle are set by calling QWizardPage::setTitle () 和 QWizardPage::setSubTitle () on the individual pages. They may be plain text or HTML (see titleFormat and subTitleFormat ). The pixmaps can be set globally for the entire wizard using setPixmap (), or on a per-page basis using QWizardPage::setPixmap ().

注册和使用字段

In many wizards, the contents of a page may affect the default values of the fields of a later page. To make it easy to communicate between pages, QWizard supports a "field" mechanism that allows you to register a field (e.g., a QLineEdit ) on a page and to access its value from any page. It is also possible to specify mandatory fields (i.e., fields that must be filled before the user can advance to the next page).

To register a field, call QWizardPage::registerField () field. For example:

ClassInfoPage::ClassInfoPage(QWidget *parent)
    : QWizardPage(parent)
{
    ...
    classNameLabel = new QLabel(tr("&Class name:"));
    classNameLineEdit = new QLineEdit;
    classNameLabel->setBuddy(classNameLineEdit);
    baseClassLabel = new QLabel(tr("B&ase class:"));
    baseClassLineEdit = new QLineEdit;
    baseClassLabel->setBuddy(baseClassLineEdit);
    qobjectMacroCheckBox = new QCheckBox(tr("Generate Q_OBJECT ¯o"));
    registerField("className*", classNameLineEdit);
    registerField("baseClass", baseClassLineEdit);
    registerField("qobjectMacro", qobjectMacroCheckBox);
    ...
}
					

The above code registers three fields, className , baseClass ,和 qobjectMacro , which are associated with three child widgets. The asterisk ( * ) next to className denotes a mandatory field.

The fields of any page are accessible from any other page. For example:

void OutputFilesPage::initializePage()
{
    QString className = field("className").toString();
    headerLineEdit->setText(className.toLower() + ".h");
    implementationLineEdit->setText(className.toLower() + ".cpp");
    outputDirLineEdit->setText(QDir::toNativeSeparators(QDir::tempPath()));
}
					

Here, we call QWizardPage::field () to access the contents of the className field (which was defined in the ClassInfoPage ) and use it to initialize the OutputFilePage . The field's contents is returned as a QVariant .

When we create a field using QWizardPage::registerField (), we pass a unique field name and a widget. We can also provide a Qt property name and a "changed" signal (a signal that is emitted when the property changes) as third and fourth arguments; however, this is not necessary for the most common Qt widgets, such as QLineEdit , QCheckBox ,和 QComboBox ,因为 QWizard knows which properties to look for.

If an asterisk ( * ) is appended to the name when the property is registered, the field is a mandatory field . When a page has mandatory fields, the 下一 and/or Finish buttons are enabled only when all mandatory fields are filled.

To consider a field "filled", QWizard simply checks that the field's current value doesn't equal the original value (the value it had when initializePage () was called). For QLineEdit and QAbstractSpinBox 子类, QWizard also checks that hasAcceptableInput() returns true, to honor any validator or mask.

QWizard 's mandatory field mechanism is provided for convenience. A more powerful (but also more cumbersome) alternative is to reimplement QWizardPage::isComplete () and to emit the QWizardPage::completeChanged () signal whenever the page becomes complete or incomplete.

The enabled/disabled state of the 下一 and/or Finish buttons is one way to perform validation on the user input. Another way is to reimplement validateCurrentPage () (or QWizardPage::validatePage ()) to perform some last-minute validation (and show an error message if the user has entered incomplete or invalid information). If the function returns true , the next page is shown (or the wizard finishes); otherwise, the current page stays up.

创建线性向导

Most wizards have a linear structure, with page 1 followed by page 2 and so on until the last page. The Class Wizard example is such a wizard. With QWizard , linear wizards are created by instantiating the QWizardPage s and inserting them using addPage (). By default, the pages are shown in the order in which they were added. For example:

ClassWizard::ClassWizard(QWidget *parent)
    : QWizard(parent)
{
    addPage(new IntroPage);
    addPage(new ClassInfoPage);
    addPage(new CodeStylePage);
    addPage(new OutputFilesPage);
    addPage(new ConclusionPage);
    ...
}
					

When a page is about to be shown, QWizard calls initializePage () (which in turn calls QWizardPage::initializePage ()) to fill the page with default values. By default, this function does nothing, but it can be reimplemented to initialize the page's contents based on other pages' fields (see the example above ).

If the user presses Back , cleanupPage () is called (which in turn calls QWizardPage::cleanupPage ()). The default implementation resets the page's fields to their original values (the values they had before initializePage () was called). If you want the Back button to be non-destructive and keep the values entered by the user, simply enable the IndependentPages 选项。

创建非线性向导

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.

In complex wizards, pages are identified by IDs. These IDs are typically defined using an enum. For example:

class LicenseWizard : public QWizard
{
    ...
    enum { Page_Intro, Page_Evaluate, Page_Register, Page_Details,
           Page_Conclusion };
    ...
};
					

The pages are inserted using setPage (), which takes an ID and an instance of QWizardPage (or of a subclass):

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);
    ...
}
					

By default, the pages are shown in increasing ID order. To provide a dynamic order that depends on the options chosen by the user, we must reimplement QWizardPage::nextId ()。例如:

int IntroPage::nextId() const
{
    if (evaluateRadioButton->isChecked()) {
        return LicenseWizard::Page_Evaluate;
    } else {
        return LicenseWizard::Page_Register;
    }
}
int EvaluatePage::nextId() const
{
    return LicenseWizard::Page_Conclusion;
}
int RegisterPage::nextId() const
{
    if (upgradeKeyLineEdit->text().isEmpty()) {
        return LicenseWizard::Page_Details;
    } else {
        return LicenseWizard::Page_Conclusion;
    }
}
int DetailsPage::nextId() const
{
    return LicenseWizard::Page_Conclusion;
}
int ConclusionPage::nextId() const
{
    return -1;
}
					

It would also be possible to put all the logic in one place, in a QWizard::nextId () reimplementation. For example:

int LicenseWizard::nextId() const
{
    switch (currentId()) {
    case Page_Intro:
        if (field("intro.evaluate").toBool()) {
            return Page_Evaluate;
        } else {
            return Page_Register;
        }
    case Page_Evaluate:
        return Page_Conclusion;
    case Page_Register:
        if (field("register.upgradeKey").toString().isEmpty()) {
            return Page_Details;
        } else {
            return Page_Conclusion;
        }
    case Page_Details:
        return Page_Conclusion;
    case Page_Conclusion:
    default:
        return -1;
    }
}
					

To start at another page than the page with the lowest ID, call setStartId ().

To test whether a page has been visited or not, call hasVisitedPage ()。例如:

void ConclusionPage::initializePage()
{
    QString licenseText;
    if (wizard()->hasVisitedPage(LicenseWizard::Page_Evaluate)) {
        licenseText = tr("<u>Evaluation License Agreement:</u> "
                         "You can use this software for 30 days and make one "
                         "backup, but you are not allowed to distribute it.");
    } else if (wizard()->hasVisitedPage(LicenseWizard::Page_Details)) {
        licenseText = tr("<u>First-Time License Agreement:</u> "
                         "You can use this software subject to the license "
                         "you will receive by email.");
    } else {
        licenseText = tr("<u>Upgrade License Agreement:</u> "
                         "This software is licensed under the terms of your "
                         "current license.");
    }
    bottomLabel->setText(licenseText);
}
					

另请参阅 QWizardPage , 类向导范例 ,和 许可向导范例 .

成员类型文档编制

enum QWizard:: WizardButton

This enum specifies the buttons in a wizard.

常量 描述
QWizard::BackButton 0 The Back button ( Go Back on macOS)
QWizard::NextButton 1 The 下一 button ( Continue on macOS)
QWizard::CommitButton 2 The Commit button
QWizard::FinishButton 3 The Finish button ( Done on macOS)
QWizard::CancelButton 4 The Cancel button (see also NoCancelButton )
QWizard::HelpButton 5 The 帮助 button (see also HaveHelpButton )
QWizard::CustomButton1 6 The first user-defined button (see also HaveCustomButton1 )
QWizard::CustomButton2 7 The second user-defined button (see also HaveCustomButton2 )
QWizard::CustomButton3 8 The third user-defined button (see also HaveCustomButton3 )

The following value is only useful when calling setButtonLayout ():

常量 描述
QWizard::Stretch 9 A horizontal stretch in the button layout

另请参阅 setButton (), setButtonText (), setButtonLayout (),和 customButtonClicked ().

enum QWizard:: WizardOption
flags QWizard:: WizardOptions

This enum specifies various options that affect the look and feel of a wizard.

常量 描述
QWizard::IndependentPages 0x00000001 The pages are independent of each other (i.e., they don't derive values from each other).
QWizard::IgnoreSubTitles 0x00000002 Don't show any subtitles, even if they are set.
QWizard::ExtendedWatermarkPixmap 0x00000004 Extend any WatermarkPixmap all the way down to the window's edge.
QWizard::NoDefaultButton 0x00000008 Don't make the 下一 or Finish button the dialog's 默认按钮 .
QWizard::NoBackButtonOnStartPage 0x00000010 Don't show the Back button on the start page.
QWizard::NoBackButtonOnLastPage 0x00000020 Don't show the Back button on the last page.
QWizard::DisabledBackButtonOnLastPage 0x00000040 Disable the Back button on the last page.
QWizard::HaveNextButtonOnLastPage 0x00000080 Show the (disabled) 下一 button on the last page.
QWizard::HaveFinishButtonOnEarlyPages 0x00000100 Show the (disabled) Finish button on non-final pages.
QWizard::NoCancelButton 0x00000200 Don't show the Cancel button.
QWizard::CancelButtonOnLeft 0x00000400 Put the Cancel button on the left of Back (rather than on the right of Finish or 下一 ).
QWizard::HaveHelpButton 0x00000800 Show the 帮助 button.
QWizard::HelpButtonOnRight 0x00001000 Put the 帮助 button on the far right of the button layout (rather than on the far left).
QWizard::HaveCustomButton1 0x00002000 Show the first user-defined button ( CustomButton1 ).
QWizard::HaveCustomButton2 0x00004000 Show the second user-defined button ( CustomButton2 ).
QWizard::HaveCustomButton3 0x00008000 Show the third user-defined button ( CustomButton3 ).
QWizard::NoCancelButtonOnLastPage 0x00010000 Don't show the Cancel button on the last page.

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

另请参阅 setOptions (), setOption (),和 testOption ().

enum QWizard:: WizardPixmap

This enum specifies the pixmaps that can be associated with a page.

常量 描述
QWizard::WatermarkPixmap 0 The tall pixmap on the left side of a ClassicStyle or ModernStyle page
QWizard::LogoPixmap 1 The small pixmap on the right side of a ClassicStyle or ModernStyle page header
QWizard::BannerPixmap 2 The pixmap that occupies the background of a ModernStyle page header
QWizard::BackgroundPixmap 3 The pixmap that occupies the background of a MacStyle wizard

另请参阅 setPixmap (), QWizardPage::setPixmap (),和 向导页面的元素 .

enum QWizard:: WizardStyle

This enum specifies the different looks supported by QWizard .

常量 描述
QWizard::ClassicStyle 0 Classic Windows look
QWizard::ModernStyle 1 Modern Windows look
QWizard::MacStyle 2 macOS look
QWizard::AeroStyle 3 Windows Aero look

另请参阅 setWizardStyle (), WizardOption ,和 向导外观和感觉 .

特性文档编制

currentId : const int

This property holds the ID of the current page

This property cannot be set directly. To change the current page, call next (), back (),或 restart ().

By default, this property has a value of -1, indicating that no page is currently shown.

访问函数:

int currentId () const

通知程序信号:

void currentIdChanged (int id )

另请参阅 currentPage ().

options : WizardOptions

This property holds the various options that affect the look and feel of the wizard

By default, the following options are set (depending on the platform):

访问函数:

WizardOptions options () const
void setOptions (WizardOptions options )

另请参阅 wizardStyle .

startId : int

This property holds the ID of the first page

If this property isn't explicitly set, this property defaults to the lowest page ID in this wizard, or -1 if no page has been inserted yet.

访问函数:

int startId () const
void setStartId (int id )

另请参阅 restart () 和 nextId ().

subTitleFormat : Qt::TextFormat

This property holds the text format used by page subtitles

默认格式为 Qt::AutoText .

访问函数:

Qt::TextFormat subTitleFormat () const
void setSubTitleFormat (Qt::TextFormat format )

另请参阅 QWizardPage::title and titleFormat .

titleFormat : Qt::TextFormat

This property holds the text format used by page titles

默认格式为 Qt::AutoText .

访问函数:

Qt::TextFormat titleFormat () const
void setTitleFormat (Qt::TextFormat format )

另请参阅 QWizardPage::title and subTitleFormat .

wizardStyle : WizardStyle

This property holds the look and feel of the wizard

默认情况下, QWizard 使用 AeroStyle on a Windows Vista system with alpha compositing enabled, regardless of the current widget style. If this is not the case, the default wizard style depends on the current widget style as follows: MacStyle is the default if the current widget style is QMacStyle, ModernStyle is the default if the current widget style is QWindowsStyle, and ClassicStyle is the default in all other cases.

访问函数:

WizardStyle wizardStyle () const
void setWizardStyle (WizardStyle style )

另请参阅 向导外观和感觉 and options .

成员函数文档编制

QWizard:: QWizard ( QWidget * parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags())

Constructs a wizard with the given parent and window flags .

另请参阅 parent () 和 windowFlags ().

QWizard:: ~QWizard ()

Destroys the wizard and its pages, releasing any allocated resources.

int QWizard:: addPage ( QWizardPage * page )

添加给定 page to the wizard, and returns the page's ID.

The ID is guaranteed to be larger than any other ID in the QWizard so far.

另请参阅 setPage (), page (),和 pageAdded ().

[slot] void QWizard:: back ()

Goes back to the previous page.

This is equivalent to pressing the Back button.

另请参阅 next (), accept (), reject (),和 restart ().

QAbstractButton *QWizard:: button ( WizardButton which ) const

Returns the button corresponding to role which .

另请参阅 setButton () 和 setButtonText ().

QString QWizard:: buttonText ( WizardButton which ) const

Returns the text on button which .

If a text has ben set using setButtonText (), this text is returned.

By default, the text on buttons depends on the wizardStyle . For example, on macOS, the 下一 button is called Continue .

另请参阅 button (), setButton (), setButtonText (), QWizardPage::buttonText (),和 QWizardPage::setButtonText ().

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

此虚函数被调用由 QWizard to clean up page id just before the user leaves it by clicking Back (unless the QWizard::IndependentPages option is set).

默认实现调用 QWizardPage::cleanupPage () on page( id ).

另请参阅 QWizardPage::cleanupPage () 和 initializePage ().

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

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

注意: 通知程序信号对于特性 currentId .

另请参阅 currentId () 和 currentPage ().

QWizardPage *QWizard:: currentPage () const

Returns a pointer to the current page, or 0 if there is no current page (e.g., before the wizard is shown).

This is equivalent to calling page( currentId ()).

另请参阅 page (), currentId (),和 restart ().

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

This signal is emitted when the user clicks a custom button. which 可以是 CustomButton1 , CustomButton2 ,或 CustomButton3 .

By default, no custom button is shown. Call setOption () 采用 HaveCustomButton1 , HaveCustomButton2 ,或 HaveCustomButton3 to have one, and use setButtonText () 或 setButton () to configure it.

另请参阅 helpRequested ().

[virtual protected] void QWizard:: done ( int result )

重实现自 QDialog::done ().

[virtual protected] bool QWizard:: event ( QEvent * event )

重实现自 QObject::event ().

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

Returns the value of the field called name .

This function can be used to access fields on any page of the wizard.

另请参阅 QWizardPage::registerField (), QWizardPage::field (),和 setField ().

bool QWizard:: hasVisitedPage ( int id ) const

返回 true if the page history contains page id ;否则,返回 false .

按下 Back marks the current page as "unvisited" again.

另请参阅 visitedPages ().

[signal] void QWizard:: helpRequested ()

This signal is emitted when the user clicks the 帮助 button.

By default, no 帮助 button is shown. Call setOption ( HaveHelpButton , true) to have one.

范例:

LicenseWizard::LicenseWizard(QWidget *parent)
    : QWizard(parent)
{
    ...
    setOption(HaveHelpButton, true);
    connect(this, &QWizard::helpRequested, this, &LicenseWizard::showHelp);
    ...
}
void LicenseWizard::showHelp()
{
    static QString lastHelpMessage;
    QString message;
    switch (currentId()) {
    case Page_Intro:
        message = tr("The decision you make here will affect which page you "
                     "get to see next.");
        break;
    ...
    default:
        message = tr("This help is likely not to be of any help.");
    }
    QMessageBox::information(this, tr("License Wizard Help"), message);
}
					

另请参阅 customButtonClicked ().

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

此虚函数被调用由 QWizard to prepare page id just before it is shown either as a result of QWizard::restart () being called, or as a result of the user clicking 下一 . (However, if the QWizard::IndependentPages option is set, this function is only called the first time the page is shown.)

By reimplementing this function, you can ensure that the page's fields are properly initialized based on fields from previous pages.

默认实现调用 QWizardPage::initializePage () on page( id ).

另请参阅 QWizardPage::initializePage () 和 cleanupPage ().

[virtual protected] bool QWizard:: nativeEvent (const QByteArray & eventType , void * message , long * result )

重实现自 QWidget::nativeEvent ().

[slot] void QWizard:: next ()

Advances to the next page.

This is equivalent to pressing the 下一 or Commit button.

另请参阅 nextId (), back (), accept (), reject (),和 restart ().

[虚拟] int QWizard:: nextId () const

此虚函数被调用由 QWizard to find out which page to show when the user clicks the 下一 button.

The return value is the ID of the next page, or -1 if no page follows.

默认实现调用 QWizardPage::nextId () on the currentPage ().

By reimplementing this function, you can specify a dynamic page order.

另请参阅 QWizardPage::nextId () 和 currentPage ().

QWizardPage *QWizard:: page ( int id ) const

Returns the page with the given id , or 0 if there is no such page.

另请参阅 addPage () 和 setPage ().

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

This signal is emitted whenever a page is added to the wizard. The page's id is passed as parameter.

该函数在 Qt 4.7 引入。

另请参阅 addPage (), setPage (),和 startId ().

QList < int > QWizard:: pageIds () const

Returns the list of page IDs.

该函数在 Qt 4.5 引入。

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

This signal is emitted whenever a page is removed from the wizard. The page's id is passed as parameter.

该函数在 Qt 4.7 引入。

另请参阅 removePage () 和 startId ().

[virtual protected] void QWizard:: paintEvent ( QPaintEvent * event )

重实现自 QWidget::paintEvent ().

QPixmap QWizard:: pixmap ( WizardPixmap which ) const

Returns the pixmap set for role which .

By default, the only pixmap that is set is the BackgroundPixmap 在 macOS。

另请参阅 setPixmap (), QWizardPage::pixmap (),和 向导页面的元素 .

void QWizard:: removePage ( int id )

Removes the page with the given id . cleanupPage () will be called if necessary.

注意: Removing a page may influence the value of the startId 特性。

该函数在 Qt 4.5 引入。

另请参阅 addPage (), setPage (), pageRemoved (),和 startId ().

[virtual protected] void QWizard:: resizeEvent ( QResizeEvent * event )

重实现自 QWidget::resizeEvent ().

[slot] void QWizard:: restart ()

Restarts the wizard at the start page. This function is called automatically when the wizard is shown.

另请参阅 startId ().

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

Sets the button corresponding to role which to button .

To add extra buttons to the wizard (e.g., a 打印 button), one way is to call setButton() with CustomButton1 to CustomButton3 , and make the buttons visible using the HaveCustomButton1 to HaveCustomButton3 选项。

另请参阅 button (), setButtonText (), setButtonLayout (),和 options .

void QWizard:: setButtonLayout (const QList < WizardButton > & layout )

Sets the order in which buttons are displayed to layout ,其中 layout 是列表化的 WizardButton

The default layout depends on the options (e.g., whether HelpButtonOnRight ) that are set. You can call this function if you need more control over the buttons' layout than what options already provides.

You can specify horizontal stretches in the layout using Stretch .

范例:

MyWizard::MyWizard(QWidget *parent)
    : QWizard(parent)
{
    ...
    QList<QWizard::WizardButton> layout;
    layout << QWizard::Stretch << QWizard::BackButton << QWizard::CancelButton
           << QWizard::NextButton << QWizard::FinishButton;
    setButtonLayout(layout);
    ...
}
					

另请参阅 setButton (), setButtonText (),和 setOptions ().

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

Sets the text on button which text .

By default, the text on buttons depends on the wizardStyle . For example, on macOS, the 下一 button is called Continue .

To add extra buttons to the wizard (e.g., a 打印 button), one way is to call setButtonText() with CustomButton1 , CustomButton2 ,或 CustomButton3 to set their text, and make the buttons visible using the HaveCustomButton1 , HaveCustomButton2 , and/or HaveCustomButton3 选项。

Button texts may also be set on a per-page basis using QWizardPage::setButtonText ().

另请参阅 buttonText (), setButton (), button (), setButtonLayout (), setOptions (),和 QWizardPage::setButtonText ().

void QWizard:: setDefaultProperty (const char * className , const char * property , const char * changedSignal )

Sets the default property for className property , and the associated change signal to be changedSignal .

The default property is used when an instance of className (or of one of its subclasses) is passed to QWizardPage::registerField () and no property is specified.

QWizard knows the most common Qt widgets. For these (or their subclasses), you don't need to specify a property changedSignal . The table below lists these widgets:

Widget 特性 Change Notification Signal
QAbstractButton bool checked toggled()
QAbstractSlider int value valueChanged()
QComboBox int currentIndex currentIndexChanged()
QDateTimeEdit QDateTime dateTime dateTimeChanged()
QLineEdit QString text textChanged()
QListWidget int currentRow currentRowChanged()
QSpinBox int value valueChanged()

另请参阅 QWizardPage::registerField ().

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

Sets the value of the field called name to value .

This function can be used to set fields on any page of the wizard.

另请参阅 QWizardPage::registerField (), QWizardPage::setField (),和 field ().

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

设置给定 option 为被启用若 on 为 true;否则,清零给定 option .

另请参阅 options , testOption (),和 setWizardStyle ().

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

添加给定 page to the wizard with the given id .

注意: Adding a page may influence the value of the startId property in case it was not set explicitly.

另请参阅 addPage (), page (),和 pageAdded ().

void QWizard:: setPixmap ( WizardPixmap which , const QPixmap & pixmap )

Sets the pixmap for role which to pixmap .

The pixmaps are used by QWizard when displaying a page. Which pixmaps are actually used depend on the wizard style .

Pixmaps can also be set for a specific page using QWizardPage::setPixmap ().

另请参阅 pixmap (), QWizardPage::setPixmap (),和 向导页面的元素 .

void QWizard:: setSideWidget ( QWidget * widget )

设置给定 widget to be shown on the left side of the wizard. For styles which use the WatermarkPixmap ( ClassicStyle and ModernStyle ) the side widget is displayed on top of the watermark, for other styles or when the watermark is not provided the side widget is displayed on the left side of the wizard.

Passing 0 shows no side widget.

widget is not 0 the wizard reparents it.

Any previous side widget is hidden.

You may call setSideWidget() with the same widget at different times.

All widgets set here will be deleted by the wizard when it is destroyed unless you separately reparent the widget after setting some other side widget (or 0).

By default, no side widget is present.

该函数在 Qt 4.7 引入。

另请参阅 sideWidget ().

[虚拟] void QWizard:: setVisible ( bool visible )

重实现自 QWidget::setVisible ().

QWidget *QWizard:: sideWidget () const

Returns the widget on the left side of the wizard or 0.

By default, no side widget is present.

该函数在 Qt 4.7 引入。

另请参阅 setSideWidget ().

[虚拟] QSize QWizard:: sizeHint () const

重实现自 QWidget::sizeHint ().

bool QWizard:: testOption ( WizardOption option ) const

返回 true 若给定 option 被启用;否则,返回 false。

另请参阅 options , setOption (),和 setWizardStyle ().

[虚拟] bool QWizard:: validateCurrentPage ()

此虚函数被调用由 QWizard when the user clicks 下一 or Finish to perform some last-minute validation. If it returns true , the next page is shown (or the wizard finishes); otherwise, the current page stays up.

默认实现调用 QWizardPage::validatePage () on the currentPage ().

When possible, it is usually better style to disable the 下一 or Finish button (by specifying mandatory fields or by reimplementing QWizardPage::isComplete ()) than to reimplement validateCurrentPage().

另请参阅 QWizardPage::validatePage () 和 currentPage ().

QList < int > QWizard:: visitedPages () const

Returns the list of IDs of visited pages, in the order in which the pages were visited.

按下 Back marks the current page as "unvisited" again.

另请参阅 hasVisitedPage ().