欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 美景 > Qt QWizard新建向导实例

Qt QWizard新建向导实例

2025/5/6 14:21:15 来源:https://blog.csdn.net/u011269801/article/details/140280913  浏览:    关键词:Qt QWizard新建向导实例

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


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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词