使用QWizard做新建向导,最简单的实例

Qt QWizard新建向导实例_QWizardPage

Qt QWizard新建向导实例_QWizardPage_02

Qt QWizard新建向导实例_qt_03

class MyWizard : public QWizard
 {
 public:    MyWizard(QWidget* parent = nullptr);
    QWizardPage* createFirstPage();
    QWizardPage* createSecondPage();
    QWizardPage* createThirdPage();
 };MyWizard::MyWizard(QWidget* parent) :
     QWizard(parent)
 {
     /*setOption( QWizard::NoBackButtonOnStartPage );*/
     //setOption( QWizard::NoBackButtonOnLastPage );
     //setOption( QWizard::NoCancelButton );    setOption(QWizard::NoBackButtonOnStartPage);//设置第一页没有上一步的按钮
     setWizardStyle(QWizard::ModernStyle);//设置上一步下一步等按钮的显示格式
     addPage(createFirstPage());//添加自己写好的QWizardPage页面
     addPage(createSecondPage());
     addPage(createThirdPage());
 }
 QWizardPage* MyWizard::createFirstPage()
 {
     QWizardPage* firstPage = new QWizardPage;
     firstPage->setTitle(tr("first"));//设置第一个QWizardPage
     QLabel* picLabel = new QLabel;
     picLabel->setPixmap(QPixmap(":/QtCanpoolDemo/res/1.jpg"));
     QHBoxLayout* firstLayout = new QHBoxLayout;
     firstLayout->addWidget(picLabel);
     firstPage->setLayout(firstLayout);    firstPage->setButtonText(QWizard::BackButton, "back");
     firstPage->setButtonText(QWizard::NextButton, "next");//为next设置一个中文的名字
     firstPage->setButtonText(QWizard::CancelButton, "cancel");
     firstPage->setButtonText(QWizard::FinishButton, "finish");
     return firstPage;
 }
 QWizardPage* MyWizard::createSecondPage()
 {
     QWizardPage* secondPage = new QWizardPage;
     secondPage->setTitle(tr("second"));
     QLabel* picLabel = new QLabel;
     picLabel->setPixmap(QPixmap(":/QtCanpoolDemo/res/2.jpg"));
     QHBoxLayout* secondLayout = new QHBoxLayout;
     secondLayout->addWidget(picLabel);
     secondPage->setLayout(secondLayout);    secondPage->setButtonText(QWizard::NextButton, "next");
     secondPage->setButtonText(QWizard::BackButton, "back");
     secondPage->setButtonText(QWizard::CancelButton, "cancel");
     secondPage->setButtonText(QWizard::FinishButton, "finish");
     return secondPage;
 }
 QWizardPage* MyWizard::createThirdPage()
 {
     QWizardPage* thirdPage = new QWizardPage;
     thirdPage->setTitle(tr("third"));
     QLabel* picLabel = new QLabel;
     picLabel->setPixmap(QPixmap(":/QtCanpoolDemo/res/3.jpg"));
     QHBoxLayout* thirdLayout = new QHBoxLayout;
     thirdLayout->addWidget(picLabel);
     thirdPage->setLayout(thirdLayout);    thirdPage->setButtonText(QWizard::NextButton, "next");
     thirdPage->setButtonText(QWizard::BackButton, "back");
     thirdPage->setButtonText(QWizard::CancelButton, "cancel");
     thirdPage->setButtonText(QWizard::FinishButton, "finish");
     return thirdPage;
 }int main(int argc, char* argv[])
 {
     QApplication app(argc, argv);    MyWizard wizard;
     wizard.show();    return app.exec();
 }
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.