QWizardPage 类是用于向导页面的基类。 更多...
头: | #include <QWizardPage> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
qmake: | QT += widgets |
继承: | QWidget |
QWizardPage (QWidget * parent = nullptr) | |
virtual | ~QWizardPage () |
QString | buttonText (QWizard::WizardButton which ) const |
virtual void | cleanupPage () |
virtual void | initializePage () |
bool | isCommitPage () const |
virtual bool | isComplete () const |
bool | isFinalPage () const |
virtual int | nextId () const |
QPixmap | pixmap (QWizard::WizardPixmap which ) const |
void | setButtonText (QWizard::WizardButton which , const QString & text ) |
void | setCommitPage (bool commitPage ) |
void | setFinalPage (bool finalPage ) |
void | setPixmap (QWizard::WizardPixmap which , const QPixmap & pixmap ) |
void | setSubTitle (const QString & subTitle ) |
void | setTitle (const QString & title ) |
QString | subTitle () const |
QString | title () const |
virtual bool | validatePage () |
void | completeChanged () |
QVariant | field (const QString & name ) const |
void | registerField (const QString & name , QWidget * widget , const char * property = nullptr, const char * changedSignal = nullptr) |
void | setField (const QString & name , const QVariant & value ) |
QWizard * | wizard () const |
QWizard represents a wizard. Each page is a QWizardPage. When you create your own wizards, you can use QWizardPage directly, or you can subclass it for more control.
A page has the following attributes, which are rendered by QWizard : title , subTitle ,和 set of pixmaps 。见 向导页面的元素 for details. Once a page is added to the wizard (using QWizard::addPage () 或 QWizard::setPage ()), wizard () returns a pointer to the associated QWizard 对象。
Page provides five virtual functions that can be reimplemented to provide custom behavior:
通常,
下一
button and the
Finish
button of a wizard are mutually exclusive. If
isFinalPage
() 返回
true
,
Finish
is available; otherwise,
下一
is available. By default,
isFinalPage
() is true only when
nextId
() returns -1. If you want to show
下一
and
Final
simultaneously for a page (letting the user perform an "early finish"), call
setFinalPage
(true) on that page. For wizards that support early finishes, you might also want to set the
HaveNextButtonOnLastPage
and
HaveFinishButtonOnEarlyPages
options on the wizard.
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. Fields are global to the entire wizard and make it easy for any single page to access information stored by another page, without having to put all the logic in QWizard or having the pages know explicitly about each other. Fields are registered using registerField () and can be accessed at any time using field () 和 setField ().
另请参阅 QWizard , 通俗向导范例 ,和 许可向导范例 .
此特性保持页面的子标题
The subtitle is shown by the QWizard , between the title and the actual page. Subtitles are optional. In ClassicStyle and ModernStyle , using subtitles is necessary to make the header appear. In MacStyle , the subtitle is shown as a text label just above the actual page.
The subtitle may be plain text or HTML, depending on the value of the QWizard::subTitleFormat 特性。
默认情况下,此特性包含空字符串。
访问函数:
QString | subTitle () const |
void | setSubTitle (const QString & subTitle ) |
另请参阅 title , QWizard::IgnoreSubTitles ,和 向导页面的元素 .
此特性保持页面的标题
The title is shown by the QWizard , above the actual page. All pages should have a title.
The title may be plain text or HTML, depending on the value of the QWizard::titleFormat 特性。
默认情况下,此特性包含空字符串。
访问函数:
QString | title () const |
void | setTitle (const QString & title ) |
[explicit]
QWizardPage::
QWizardPage
(
QWidget
*
parent
= nullptr)
Constructs a wizard page with the given parent .
When the page is inserted into a wizard using QWizard::addPage () 或 QWizard::setPage (), the parent is automatically set to be the wizard.
另请参阅 wizard ().
[virtual noexcept]
QWizardPage::
~QWizardPage
()
析构函数。
Returns the text on button which on this page.
If a text has ben set using setButtonText (), this text is returned. Otherwise, if a text has been set using QWizard::setButtonText (), this text is returned.
By default, the text on buttons depends on the QWizard::wizardStyle . For example, on macOS, the 下一 button is called Continue .
另请参阅 setButtonText (), QWizard::buttonText (),和 QWizard::setButtonText ().
[虚拟]
void
QWizardPage::
cleanupPage
()
此虚函数被调用由 QWizard::cleanupPage () when the user leaves the page by clicking Back (unless the QWizard::IndependentPages option is set).
The default implementation resets the page's fields to their original values (the values they had before initializePage () was called).
另请参阅 QWizard::cleanupPage (), initializePage (),和 QWizard::IndependentPages .
[signal]
void
QWizardPage::
completeChanged
()
This signal is emitted whenever the complete state of the page (i.e., the value of isComplete ()) changes.
If you reimplement isComplete (), make sure to emit completeChanged() whenever the value of isComplete () changes, to ensure that QWizard updates the enabled or disabled state of its buttons.
另请参阅 isComplete ().
[protected]
QVariant
QWizardPage::
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. It is equivalent to calling wizard ()-> field( name ) .
范例:
const QString emailAddress = field("details.email").toString(); licenseText = tr("<u>First-Time License Agreement:</u> " "You can use this software subject to the license " "you will receive by email sent to %1.").arg(emailAddress);
另请参阅 QWizard::field (), setField (),和 registerField ().
[虚拟]
void
QWizardPage::
initializePage
()
此虚函数被调用由 QWizard::initializePage () to prepare the page 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. For example:
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)) { const QString emailAddress = field("details.email").toString(); licenseText = tr("<u>First-Time License Agreement:</u> " "You can use this software subject to the license " "you will receive by email sent to %1.").arg(emailAddress); } else { licenseText = tr("<u>Upgrade License Agreement:</u> " "This software is licensed under the terms of your " "current license."); } bottomLabel->setText(licenseText); }
默认实现什么都不做。
另请参阅 QWizard::initializePage (), cleanupPage (),和 QWizard::IndependentPages .
返回
true
if this page is a commit page; otherwise returns
false
.
另请参阅 setCommitPage ().
[虚拟]
bool
QWizardPage::
isComplete
() const
此虚函数被调用由 QWizard to determine whether the 下一 or Finish button should be enabled or disabled.
默认实现返回
true
if all
mandatory fields
are filled; otherwise, it returns
false
.
If you reimplement this function, make sure to emit completeChanged (), from the rest of your implementation, whenever the value of isComplete() changes. This ensures that QWizard updates the enabled or disabled state of its buttons. An example of the reimplementation is available here .
另请参阅 completeChanged () 和 isFinalPage ().
此函数被调用通过 QWizard to determine whether the Finish button should be shown for this page or not.
By default, it returns
true
if there is no next page (i.e.,
nextId
() returns -1); otherwise, it returns
false
.
By explicitly calling setFinalPage (true), you can let the user perform an "early finish".
另请参阅 isComplete () 和 QWizard::HaveFinishButtonOnEarlyPages .
[虚拟]
int
QWizardPage::
nextId
() const
此虚函数被调用由 QWizard::nextId () 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.
By default, this function returns the lowest ID greater than the ID of the current page, or -1 if there is no such ID.
By reimplementing this function, you can specify a dynamic page order. For example:
int IntroPage::nextId() const { if (evaluateRadioButton->isChecked()) { return LicenseWizard::Page_Evaluate; } else { return LicenseWizard::Page_Register; } }
另请参阅 QWizard::nextId ().
Returns the pixmap set for role which .
Pixmaps can also be set for the entire wizard using QWizard::setPixmap (), in which case they apply for all pages that don't specify a pixmap.
另请参阅 setPixmap (), QWizard::pixmap (),和 向导页面的元素 .
[protected]
void
QWizardPage::
registerField
(const
QString
&
name
,
QWidget
*
widget
, const
char
*
property
= nullptr, const
char
*
changedSignal
= nullptr)
Creates a field called name 关联给定 property 为给定 widget . From then on, that property becomes accessible using field () 和 setField ().
Fields are global to the entire wizard and make it easy for any single page to access information stored by another page, without having to put all the logic in QWizard or having the pages know explicitly about each other.
若
name
ends with an asterisk (
*
), 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. This requires a
changedSignal
to be specified, to tell
QWizard
to recheck the value stored by the mandatory field.
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 () |
可以使用 QWizard::setDefaultProperty () to add entries to this table or to override existing entries.
To consider a field "filled", QWizard simply checks that their current value doesn't equal their original value (the value they had before initializePage () was called). For QLineEdit , it also checks that hasAcceptableInput () returns true, to honor any validator or mask.
QWizard 's mandatory field mechanism is provided for convenience. It can be bypassed by reimplementing QWizardPage::isComplete ().
另请参阅 field (), setField (),和 QWizard::setDefaultProperty ().
Sets the text on button which 到 text on this page.
By default, the text on buttons depends on the QWizard::wizardStyle , but may be redefined for the wizard as a whole using QWizard::setButtonText ().
另请参阅 buttonText (), QWizard::setButtonText (),和 QWizard::buttonText ().
Sets this page to be a commit page if commitPage is true; otherwise, sets it to be a normal page.
A commit page is a page that represents an action which cannot be undone by clicking Back or Cancel .
A Commit button replaces the 下一 button on a commit page. Clicking this button simply calls QWizard::next () just like clicking 下一 does.
A page entered directly from a commit page has its Back button disabled.
另请参阅 isCommitPage ().
[protected]
void
QWizardPage::
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. It is equivalent to calling wizard ()-> setField( name , value ) .
另请参阅 QWizard::setField (), field (),和 registerField ().
Explicitly sets this page to be final if finalPage 为 true。
After calling setFinalPage(true),
isFinalPage
() 返回
true
和
Finish
button is visible (and enabled if
isComplete
() 返回 true)。
After calling setFinalPage(false),
isFinalPage
() 返回
true
if
nextId
() returns -1; otherwise, it returns
false
.
另请参阅 isFinalPage (), isComplete (),和 QWizard::HaveFinishButtonOnEarlyPages .
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 the entire wizard using QWizard::setPixmap (), in which case they apply for all pages that don't specify a pixmap.
另请参阅 pixmap (), QWizard::setPixmap (),和 向导页面的元素 .
[虚拟]
bool
QWizardPage::
validatePage
()
此虚函数被调用由
QWizard::validateCurrentPage
() 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.
默认实现返回
true
.
When possible, it is usually better style to disable the 下一 or Finish button (by specifying mandatory fields or reimplementing isComplete ()) than to reimplement validatePage().
另请参阅 QWizard::validateCurrentPage () 和 isComplete ().
[protected]
QWizard
*QWizardPage::
wizard
() const
Returns the wizard associated with this page, or
nullptr
if this page hasn't been inserted into a
QWizard
yet.
另请参阅 QWizard::addPage () 和 QWizard::setPage ().