QWizard类提供了一个向导对话框的框架。
向导就是包含一组顺序的对话框页面的特定类型的输入对话框。向导的目的是让用户一步一步地完成一个过程。向导对于复杂或者偶尔发生的并且人们发现它很难学会或者执行的任务很有用处。
自己根据文档完成了一个小的例子,以备不时之需。
#include "mywizard.h"
MyWizard::MyWizard(QWidget *parent) :
QWizard(parent)
{
/*setOption( QWizard::NoBackButtonOnStartPage );
setOption( QWizard::NoBackButtonOnLastPage );
setOption( QWizard::NoCancelButton );*/
this->setOption( QWizard::NoBackButtonOnStartPage );//设置第一页没有上一步的按钮
this->setWizardStyle( QWizard::ModernStyle );//设置上一步下一步等按钮的显示格式
this->addPage(createFirstPage());//添加自己写好的QWizardPage页面
this->addPage(createSecondPage());
this->addPage(createThirdPage());
}
QWizardPage *MyWizard::createFirstPage()
{
QWizardPage *firstPage = new QWizardPage;
firstPage->setTitle(tr("第一步"));//设置第一个QWizardPage
QLabel *picLabel = new QLabel;
picLabel->setPixmap(QPixmap(":/image/first.jpg"));
QHBoxLayout *firstLayout = new QHBoxLayout;
firstLayout->addWidget(picLabel);
firstPage->setLayout(firstLayout);
firstPage->setButtonText(QWizard::BackButton,"上一步");
firstPage->setButtonText(QWizard::NextButton,"下一步");//为next设置一个中文的名字
firstPage->setButtonText(QWizard::CancelButton,"取消");
firstPage->setButtonText(QWizard::FinishButton,"完成");
return firstPage;
}
QWizardPage *MyWizard::createSecondPage()
{
QWizardPage *secondPage = new QWizardPage;
secondPage->setTitle(tr("第二步"));
QLabel *picLabel = new QLabel;
picLabel->setPixmap(QPixmap(":/image/second.jpg"));
QHBoxLayout *secondLayout = new QHBoxLayout;
secondLayout->addWidget(picLabel);
secondPage->setLayout(secondLayout);
secondPage->setButtonText(QWizard::NextButton,"下一步");
secondPage->setButtonText(QWizard::BackButton,"上一步");
secondPage->setButtonText(QWizard::CancelButton,"取消");
secondPage->setButtonText(QWizard::FinishButton,"完成");
return secondPage;
}
QWizardPage *MyWizard::createThirdPage()
{
QWizardPage *thirdPage = new QWizardPage;
thirdPage->setTitle(tr("第三步"));
QLabel *picLabel = new QLabel;
picLabel->setPixmap(QPixmap(":/image/third.jpg"));
QHBoxLayout *thirdLayout = new QHBoxLayout;
thirdLayout->addWidget(picLabel);
thirdPage->setLayout(thirdLayout);
thirdPage->setButtonText(QWizard::NextButton,"下一步");
thirdPage->setButtonText(QWizard::BackButton,"上一步");
thirdPage->setButtonText(QWizard::CancelButton,"取消");
thirdPage->setButtonText(QWizard::FinishButton,"完成");
return thirdPage;
}
截图