QWizard

本例展示怎么用QWizard实现线性向导。例子通过向导为我们在指定目录地点生成了c++代码。


大多数的向导都是线性结构的,一页跟着一页,直到最后一页。一些向导也可能更复杂,以致根据用户输入的信息提供不同的漫游路径。之后有一个License Wizard的例子展示了这样的向导。


类向导例子由下面的类组成:

1. Class Wizard,继承自QWizard

2. IntroPage, ClassInfoPage, CodeStylePage, OutputFilesPageConclusionPage都是QWizardPage的子类。QWizard实现向导页。


本例的ClassWizard类只重新实现了accept()槽,当用户点击Finish的时候就会调用这个槽。

QWizard是继承自QDialog的,而每一个向导页面是由QWizardPageQWidget的一个子类)来执行的,采用addPage()来增加创建的QWizardPage

QWizardPage可以添加标题,标题会显示在页的最左上方。setTitle()。还可以设置子标题,子标题跟着标题的下面的位置,起到说明的作用。setSubTitle().

可以用setPixmap来为向导提供图片,void QWizard::setPixmap ( WizardPixmap which, const QPixmap & pixmap )


向导有四种风格:ClassicStyleModernStyleMacStyleAeroStyle(setWizardStyle设置)

枚举类WizardPixmap有四个值:

QWizard::WatermarkPixmap:ClassicStyleModernStyle页面的左侧设置图片

QWizard::LogoPixmap:ClassicStyleModernStyle 右侧设置图片

QWizard::BannerPixmap:ModernStyle设置的背景图片

QWizard::BackgroundPixmap:MacStyle设置背景图片


在很多向导中,页的内容会被一些默认的值或者用户设置的值影响,QWizard提供一个叫“field(叫它域吧)的机制。它允许在向导页上注册一个域(例如一个QLineEdit),并可以在任何其他页中存取它的值。可以通过QWizardPage::registerField()调用域。这个域也可以是托管的(mandatory)域(带星号“*”),托管的域必须填充才能进入到下一个页。例如:registerField("className*", classNameLineEdit);注册好了以后就可以用field(“**”)使用了。例如:QString className = field("className").toString();域的内容是作为QVariant返回的。


向导可以为自己添加按钮等控件用来指导向导页面的翻转移动,以及结束。NextFinish按钮是否用一个方法是通过用户的输入,另一个方法是重新实现validateCurrentPage()QWizardPage::validatePage(),通过它去批准是否生效还可以通过它去确认用户的输入是否符合要求。


下面看代码咯~:

[cpp] view plain copy
  1. int main(int argc, char *argv[])  
  2. {  
  3.     Q_INIT_RESOURCE(classwizard);  
  4.       
  5.     QApplication app(argc, argv);  
  6.   
  7.     // 添加国际化支持  
  8.     QString translatorFileName = QLatin1String("qt_");  
  9.     translatorFileName += QLocale::system().name();  
  10.     QTranslator *translator = new QTranslator(&app);  
  11.     if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))  
  12.         app.installTranslator(translator);  
  13.   
  14.     ClassWizard wizard;  
  15.     wizard.show();  
  16.     return app.exec();  
  17. }  



[cpp] view plain copy
  1. //! [0]  
  2. class ClassWizard : public QWizard  
  3. {  
  4.     Q_OBJECT  
  5.   
  6. public:  
  7.     ClassWizard(QWidget *parent = 0);  
  8.   
  9.     void accept();  
  10. };  
  11. //! [0]  
  12.   
  13. //! [1]  
  14. // 介绍页只有一个标签  
  15. class IntroPage : public QWizardPage  
  16. {  
  17.     Q_OBJECT  
  18.   
  19. public:  
  20.     IntroPage(QWidget *parent = 0);  
  21.   
  22. private:  
  23.     QLabel *label;  
  24. };  
  25. //! [1]  
  26.   
  27. //! [2]  
  28. // 类信息的东西较多  
  29. class ClassInfoPage : public QWizardPage  
  30. {  
  31.     Q_OBJECT  
  32.   
  33. public:  
  34.     ClassInfoPage(QWidget *parent = 0);  
  35.   
  36. private:  
  37.     QLabel *classNameLabel;  
  38.     QLabel *baseClassLabel;  
  39.     QLineEdit *classNameLineEdit;  
  40.     QLineEdit *baseClassLineEdit;  
  41.     QCheckBox *qobjectMacroCheckBox;  
  42.     QGroupBox *groupBox;  
  43.     QRadioButton *qobjectCtorRadioButton;  
  44.     QRadioButton *qwidgetCtorRadioButton;  
  45.     QRadioButton *defaultCtorRadioButton;  
  46.     QCheckBox *copyCtorCheckBox;  
  47. };  
  48. //! [2]  
  49.   
  50. //! [3]  
  51. // 代码风格页  
  52. class CodeStylePage : public QWizardPage  
  53. {  
  54.     Q_OBJECT  
  55.   
  56. public:  
  57.     CodeStylePage(QWidget *parent = 0);  
  58.   
  59. protected:  
  60.     void initializePage();  
  61.   
  62. private:  
  63.     QCheckBox *commentCheckBox;  
  64.     QCheckBox *protectCheckBox;  
  65.     QCheckBox *includeBaseCheckBox;  
  66.     QLabel *macroNameLabel;  
  67.     QLabel *baseIncludeLabel;  
  68.     QLineEdit *macroNameLineEdit;  
  69.     QLineEdit *baseIncludeLineEdit;  
  70. };  
  71. //! [3]  
  72.   
  73. // 输出文件页,输出地址+头文件+实现文件  
  74. // 重写了initializePage()它在QWizard::restart或点击NEXT时被调用  
  75. class OutputFilesPage : public QWizardPage  
  76. {  
  77.     Q_OBJECT  
  78.   
  79. public:      
  80.     OutputFilesPage(QWidget *parent = 0);  
  81.   
  82. protected:  
  83.     void initializePage();  
  84.   
  85. private:  
  86.     QLabel *outputDirLabel;  
  87.     QLabel *headerLabel;  
  88.     QLabel *implementationLabel;  
  89.     QLineEdit *outputDirLineEdit;  
  90.     QLineEdit *headerLineEdit;  
  91.     QLineEdit *implementationLineEdit;  
  92. };  
  93.   
  94. // 最后的结论页,也只有个一个标签  
  95. class ConclusionPage : public QWizardPage  
  96. {  
  97.     Q_OBJECT  
  98.   
  99. public:  
  100.     ConclusionPage(QWidget *parent = 0);  
  101.   
  102. protected:  
  103.     void initializePage();  
  104.   
  105. private:  
  106.     QLabel *label;  
  107. };  

[cpp] view plain copy
  1. //! [0] //! [1]  
  2. ClassWizard::ClassWizard(QWidget *parent)  
  3.     : QWizard(parent)  
  4. {  
  5.     addPage(new IntroPage);        // 添加定义的五个页面  
  6.     addPage(new ClassInfoPage);  
  7.     addPage(new CodeStylePage);  
  8.     addPage(new OutputFilesPage);  
  9.     addPage(new ConclusionPage);  
  10. //! [0]  
  11.   
  12.     setWizardStyle(ModernStyle); // 如果你用的是win7或vista默认的风格是AeroStyle  
  13.     setPixmap(QWizard::BannerPixmap, QPixmap(":/images/banner.png"));  
  14.     setPixmap(QWizard::BackgroundPixmap, QPixmap(":/images/background.png"));  
  15.   
  16.     setWindowTitle(tr("Class Wizard"));  
  17. //! [2]  
  18. }  
  19. //! [1] //! [2]  
  20.   
  21. //! [3]  
  22. // 最后完成时执行该槽,将信息写入生成文件  
  23. void ClassWizard::accept()  
  24. //! [3] //! [4]  
  25. {  
  26.     QByteArray className = field("className").toByteArray();  
  27.     QByteArray baseClass = field("baseClass").toByteArray();  
  28.     QByteArray macroName = field("macroName").toByteArray();  
  29.     QByteArray baseInclude = field("baseInclude").toByteArray();  
  30.   
  31.     QString outputDir = field("outputDir").toString();  
  32.     QString header = field("header").toString();  
  33.     QString implementation = field("implementation").toString();  
  34. //! [4]  
  35.   
  36.     QByteArray block;  
  37.   
  38.     if (field("comment").toBool()) {  
  39.         block += "/*\n";  
  40.         block += "    " + header.toAscii() + "\n";  // 头文件  
  41.         block += "*/\n";  
  42.         block += "\n";  
  43.     }  
  44.     if (field("protect").toBool()) {  
  45.         block += "#ifndef " + macroName + "\n";  
  46.         block += "#define " + macroName + "\n";  
  47.         block += "\n";  
  48.     }  
  49.     if (field("includeBase").toBool()) {  
  50.         block += "#include " + baseInclude + "\n";  // 引用头文件  
  51.         block += "\n";  
  52.     }  
  53.   
  54.     block += "class " + className;                  // 定义类  
  55.     if (!baseClass.isEmpty())  
  56.         block += " : public " + baseClass;  
  57.     block += "\n";  
  58.     block += "{\n";  
  59.   
  60.     /* qmake ignore Q_OBJECT */  
  61.   
  62.     if (field("qobjectMacro").toBool()) {  
  63.         block += "    Q_OBJECT\n";  
  64.         block += "\n";  
  65.     }  
  66.     block += "public:\n";  
  67.   
  68.     if (field("qobjectCtor").toBool()) {            // 定义各种风格构造函数  
  69.         block += "    " + className + "(QObject *parent = 0);\n";  
  70.     } else if (field("qwidgetCtor").toBool()) {  
  71.         block += "    " + className + "(QWidget *parent = 0);\n";  
  72.     } else if (field("defaultCtor").toBool()) {  
  73.         block += "    " + className + "();\n";  
  74.         if (field("copyCtor").toBool()) {  
  75.             block += "    " + className + "(const " + className + " &other);\n";  
  76.             block += "\n";  
  77.             block += "    " + className + " &operator=" + "(const " + className  
  78.                      + " &other);\n";  
  79.         }  
  80.     }  
  81.     block += "};\n";  
  82.   
  83.     if (field("protect").toBool()) {  
  84.         block += "\n";  
  85.         block += "#endif\n";  
  86.     }  
  87.   
  88.     QFile headerFile(outputDir + "/" + header);  
  89.     if (!headerFile.open(QFile::WriteOnly | QFile::Text)) {  
  90.         QMessageBox::warning(0, QObject::tr("Simple Wizard"),  
  91.                              QObject::tr("Cannot write file %1:\n%2")  
  92.                              .arg(headerFile.fileName())  
  93.                              .arg(headerFile.errorString()));  
  94.         return;  
  95.     }  
  96.     headerFile.write(block);  
  97.   
  98.     block.clear();  
  99.   
  100.     if (field("comment").toBool()) {                // 一些说明  
  101.         block += "/*\n";  
  102.         block += "    " + implementation.toAscii() + "\n";  
  103.         block += "*/\n";  
  104.         block += "\n";  
  105.     }  
  106.     block += "#include \"" + header.toAscii() + "\"\n";  
  107.     block += "\n";  
  108.   
  109.     if (field("qobjectCtor").toBool()) {             // QObject风格的构造器  
  110.         block += className + "::" + className + "(QObject *parent)\n";  
  111.         block += "    : " + baseClass + "(parent)\n";  
  112.         block += "{\n";  
  113.         block += "}\n";  
  114.     } else if (field("qwidgetCtor").toBool()) {       // QWidget风格的构造器  
  115.         block += className + "::" + className + "(QWidget *parent)\n";  
  116.         block += "    : " + baseClass + "(parent)\n";  
  117.         block += "{\n";  
  118.         block += "}\n";  
  119.     } else if (field("defaultCtor").toBool()) {        // 默认构造函数  
  120.         block += className + "::" + className + "()\n";  
  121.         block += "{\n";  
  122.         block += "    // missing code\n";  
  123.         block += "}\n";  
  124.   
  125.         if (field("copyCtor").toBool()) {              // 复制构造函数  
  126.             block += "\n";  
  127.             block += className + "::" + className + "(const " + className  
  128.                      + " &other)\n";  
  129.             block += "{\n";  
  130.             block += "    *this = other;\n";  
  131.             block += "}\n";  
  132.             block += "\n";  
  133.             block += className + " &" + className + "::operator=(const "  
  134.                      + className + " &other)\n";  
  135.             block += "{\n";  
  136.             if (!baseClass.isEmpty())  
  137.                 block += "    " + baseClass + "::operator=(other);\n";  
  138.             block += "    // missing code\n";  
  139.             block += "    return *this;\n";  
  140.             block += "}\n";  
  141.         }  
  142.     }  
  143.   
  144.     // 执行生成文件  
  145.     QFile implementationFile(outputDir + "/" + implementation);  
  146.     if (!implementationFile.open(QFile::WriteOnly | QFile::Text)) {  
  147.         QMessageBox::warning(0, QObject::tr("Simple Wizard"),  
  148.                              QObject::tr("Cannot write file %1:\n%2")  
  149.                              .arg(implementationFile.fileName())  
  150.                              .arg(implementationFile.errorString()));  
  151.         return;  
  152.     }  
  153.     implementationFile.write(block);  
  154.   
  155. //! [5]  
  156.     QDialog::accept();  
  157. //! [5] //! [6]  
  158. }  
  159. //! [6]  
  160.   
  161. //! [7]  
  162. IntroPage::IntroPage(QWidget *parent)  
  163.     : QWizardPage(parent)  
  164. {  
  165.     // 设置标题  
  166.     setTitle(tr("Introduction"));  
  167.     // 设置图片  
  168.     setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark1.png"));  
  169.   
  170.     // 展示标签  
  171.     label = new QLabel(tr("This wizard will generate a skeleton C++ class "  
  172.                           "definition, including a few functions. You simply "  
  173.                           "need to specify the class name and set a few "  
  174.                           "options to produce a header file and an "  
  175.                           "implementation file for your new C++ class."));  
  176.     label->setWordWrap(true);  // 由于标签比较长,在分开的地方需要设置断开到下一行  
  177.   
  178.     QVBoxLayout *layout = new QVBoxLayout; // 布局管理  
  179.     layout->addWidget(label);  
  180.     setLayout(layout);  
  181. }  
  182. //! [7]  
  183.   
  184. //! [8] //! [9]  
  185. ClassInfoPage::ClassInfoPage(QWidget *parent)  
  186.     : QWizardPage(parent)  
  187. {  
  188. //! [8]  
  189.     // 标题和子标题  
  190.     setTitle(tr("Class Information"));  
  191.     setSubTitle(tr("Specify basic information about the class for which you "  
  192.                    "want to generate skeleton source code files."));  
  193.     setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo1.png")); // Logo  
  194.   
  195. //! [10]  
  196.     // 设置部件  
  197.     classNameLabel = new QLabel(tr("&Class name:"));  
  198.     classNameLineEdit = new QLineEdit;  
  199.     classNameLabel->setBuddy(classNameLineEdit);  
  200.   
  201.     baseClassLabel = new QLabel(tr("B&ase class:"));  
  202.     baseClassLineEdit = new QLineEdit;  
  203.     baseClassLabel->setBuddy(baseClassLineEdit);  
  204.   
  205.     qobjectMacroCheckBox = new QCheckBox(tr("Generate Q_OBJECT ¯o"));  
  206.   
  207. //! [10]  
  208.     groupBox = new QGroupBox(tr("C&onstructor"));  
  209. //! [9]  
  210.   
  211.     qobjectCtorRadioButton = new QRadioButton(tr("&QObject-style constructor"));  
  212.     qwidgetCtorRadioButton = new QRadioButton(tr("Q&Widget-style constructor"));  
  213.     defaultCtorRadioButton = new QRadioButton(tr("&Default constructor"));  
  214.     copyCtorCheckBox = new QCheckBox(tr("&Generate copy constructor and "  
  215.                                         "operator="));  
  216.   
  217.     defaultCtorRadioButton->setChecked(true);  
  218.   
  219.     connect(defaultCtorRadioButton, SIGNAL(toggled(bool)),  
  220.             copyCtorCheckBox, SLOT(setEnabled(bool)));  
  221.   
  222. //! [11] //! [12]  
  223.     // 注册域  
  224.     registerField("className*", classNameLineEdit);  
  225.     registerField("baseClass", baseClassLineEdit);  
  226.     registerField("qobjectMacro", qobjectMacroCheckBox);  
  227. //! [11]  
  228.     registerField("qobjectCtor", qobjectCtorRadioButton);  
  229.     registerField("qwidgetCtor", qwidgetCtorRadioButton);  
  230.     registerField("defaultCtor", defaultCtorRadioButton);  
  231.     registerField("copyCtor", copyCtorCheckBox);  
  232.   
  233.     QVBoxLayout *groupBoxLayout = new QVBoxLayout;  // 组框内的布局  
  234. //! [12]  
  235.     groupBoxLayout->addWidget(qobjectCtorRadioButton);  
  236.     groupBoxLayout->addWidget(qwidgetCtorRadioButton);  
  237.     groupBoxLayout->addWidget(defaultCtorRadioButton);  
  238.     groupBoxLayout->addWidget(copyCtorCheckBox);  
  239.     groupBox->setLayout(groupBoxLayout);  
  240.   
  241.     QGridLayout *layout = new QGridLayout;        // InfoPage的布局  
  242.     layout->addWidget(classNameLabel, 0, 0);  
  243.     layout->addWidget(classNameLineEdit, 0, 1);  
  244.     layout->addWidget(baseClassLabel, 1, 0);  
  245.     layout->addWidget(baseClassLineEdit, 1, 1);  
  246.     layout->addWidget(qobjectMacroCheckBox, 2, 0, 1, 2);  
  247.     layout->addWidget(groupBox, 3, 0, 1, 2);  
  248.     setLayout(layout);  
  249. //! [13]  
  250. }  
  251. //! [13]  
  252.   
  253. //! [14]  
  254. CodeStylePage::CodeStylePage(QWidget *parent)  
  255.     : QWizardPage(parent)  
  256. {  
  257.     setTitle(tr("Code Style Options"));  
  258.     setSubTitle(tr("Choose the formatting of the generated code."));  
  259.     setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo2.png"));  
  260.   
  261.     commentCheckBox = new QCheckBox(tr("&Start generated files with a "  
  262. //! [14]  
  263.                                        "comment"));  
  264.     commentCheckBox->setChecked(true);    // 初始化为勾上  
  265.   
  266.     protectCheckBox = new QCheckBox(tr("&Protect header file against multiple "  
  267.                                        "inclusions"));  
  268.     protectCheckBox->setChecked(true);   // 初始化为勾上  
  269.   
  270.     macroNameLabel = new QLabel(tr("&Macro name:"));  // label和lineEdit  
  271.     macroNameLineEdit = new QLineEdit;  
  272.     macroNameLabel->setBuddy(macroNameLineEdit);  
  273.   
  274.     // 跟上一页的基类关联  
  275.     includeBaseCheckBox = new QCheckBox(tr("&Include base class definition"));  
  276.     baseIncludeLabel = new QLabel(tr("Base class include:"));  
  277.     baseIncludeLineEdit = new QLineEdit;  
  278.     baseIncludeLabel->setBuddy(baseIncludeLineEdit);  
  279.   
  280.     // protectCheckBox和它下方的macroNameLabel,macroNameLineEdit保持同步  
  281.     connect(protectCheckBox, SIGNAL(toggled(bool)),  
  282.             macroNameLabel, SLOT(setEnabled(bool)));  
  283.     connect(protectCheckBox, SIGNAL(toggled(bool)),  
  284.             macroNameLineEdit, SLOT(setEnabled(bool)));  
  285.     // includeBaseCheckBox和它右边的baseIncludeLabel,baseIncludeLineEdit保持同步  
  286.     connect(includeBaseCheckBox, SIGNAL(toggled(bool)),  
  287.             baseIncludeLabel, SLOT(setEnabled(bool)));  
  288.     connect(includeBaseCheckBox, SIGNAL(toggled(bool)),  
  289.             baseIncludeLineEdit, SLOT(setEnabled(bool)));  
  290.   
  291.     // 注册域  
  292.     registerField("comment", commentCheckBox);  
  293.     registerField("protect", protectCheckBox);  
  294.     registerField("macroName", macroNameLineEdit);  
  295.     registerField("includeBase", includeBaseCheckBox);  
  296.     registerField("baseInclude", baseIncludeLineEdit);  
  297.   
  298.     QGridLayout *layout = new QGridLayout;   // 布局  
  299.     layout->setColumnMinimumWidth(0, 20);    // 设置第一列的最小宽20像素  
  300.     layout->addWidget(commentCheckBox, 0, 0, 1, 3);  
  301.     layout->addWidget(protectCheckBox, 1, 0, 1, 3);  
  302.     layout->addWidget(macroNameLabel, 2, 1);  
  303.     layout->addWidget(macroNameLineEdit, 2, 2);  
  304.     layout->addWidget(includeBaseCheckBox, 3, 0, 1, 3);  
  305.     layout->addWidget(baseIncludeLabel, 4, 1);  
  306.     layout->addWidget(baseIncludeLineEdit, 4, 2);  
  307. //! [15]  
  308.     setLayout(layout);  
  309. }  
  310. //! [15]  
  311.   
  312. //! [16]  
  313. // 上一页类信息的基类和宏影响这一页,上一页点NEXT时触发本槽  
  314. void CodeStylePage::initializePage()  
  315. {  
  316.     QString className = field("className").toString();  
  317.     macroNameLineEdit->setText(className.toUpper() + "_H");// 定义宏  
  318.   
  319.     QString baseClass = field("baseClass").toString();  
  320.   
  321.     // 上一页中定义了基类就将本页的相关控件设置  
  322.     includeBaseCheckBox->setChecked(!baseClass.isEmpty());  
  323.     includeBaseCheckBox->setEnabled(!baseClass.isEmpty());  
  324.     baseIncludeLabel->setEnabled(!baseClass.isEmpty());  
  325.     baseIncludeLineEdit->setEnabled(!baseClass.isEmpty());  
  326.   
  327.     if (baseClass.isEmpty()) {  // baseClass没有设置  
  328.         baseIncludeLineEdit->clear();  
  329.     } else if (QRegExp("Q[A-Z].*").exactMatch(baseClass)) {  // baseClass设置了为Q*.*,为Qt库中的类  
  330.         baseIncludeLineEdit->setText("<" + baseClass + ">");  
  331.     } else {                                                // 其他情况  
  332.         baseIncludeLineEdit->setText("\"" + baseClass.toLower() + ".h\"");  
  333.     }  
  334. }  
  335. //! [16]  
  336.   
  337. OutputFilesPage::OutputFilesPage(QWidget *parent)  
  338.     : QWizardPage(parent)  
  339. {  
  340.     // 标题 子标题 logo  
  341.     setTitle(tr("Output Files"));  
  342.     setSubTitle(tr("Specify where you want the wizard to put the generated "  
  343.                    "skeleton code."));  
  344.     setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo3.png"));  
  345.   
  346.     // 创建页中的窗体部件  
  347.     outputDirLabel = new QLabel(tr("&Output directory:"));  
  348.     outputDirLineEdit = new QLineEdit;  
  349.     outputDirLabel->setBuddy(outputDirLineEdit);  
  350.   
  351.     headerLabel = new QLabel(tr("&Header file name:"));  
  352.     headerLineEdit = new QLineEdit;  
  353.     headerLabel->setBuddy(headerLineEdit);  
  354.   
  355.     implementationLabel = new QLabel(tr("&Implementation file name:"));  
  356.     implementationLineEdit = new QLineEdit;  
  357.     implementationLabel->setBuddy(implementationLineEdit);  
  358.   
  359.     // 注册域  
  360.     registerField("outputDir*", outputDirLineEdit);  
  361.     registerField("header*", headerLineEdit);  
  362.     registerField("implementation*", implementationLineEdit);  
  363.   
  364.     // 布局  
  365.     QGridLayout *layout = new QGridLayout;  
  366.     layout->addWidget(outputDirLabel, 0, 0);  
  367.     layout->addWidget(outputDirLineEdit, 0, 1);  
  368.     layout->addWidget(headerLabel, 1, 0);  
  369.     layout->addWidget(headerLineEdit, 1, 1);  
  370.     layout->addWidget(implementationLabel, 2, 0);  
  371.     layout->addWidget(implementationLineEdit, 2, 1);  
  372.     setLayout(layout);  
  373. }  
  374.   
  375. //! [17]  
  376. void OutputFilesPage::initializePage()  
  377. {  
  378.     QString className = field("className").toString();  
  379.     headerLineEdit->setText(className.toLower() + ".h");  // 头文件  
  380.     implementationLineEdit->setText(className.toLower() + ".cpp"); // 实现文件  
  381.     // 输出路径初始化为系统temp的路径  
  382.     // convertSeparators()是解决不同系统中分隔符的问题  
  383.     outputDirLineEdit->setText(QDir::convertSeparators(QDir::tempPath()));  
  384. }  
  385. //! [17]  
  386.   
  387. ConclusionPage::ConclusionPage(QWidget *parent)  
  388.     : QWizardPage(parent)  
  389. {  
  390.     setTitle(tr("Conclusion"));  
  391.     setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark2.png"));  
  392.   
  393.     label = new QLabel;  // 创建label  
  394.     label->setWordWrap(true);  
  395.   
  396.     QVBoxLayout *layout = new QVBoxLayout;  
  397.     layout->addWidget(label);  
  398.     setLayout(layout);  
  399. }  
  400.   
  401. void ConclusionPage::initializePage()  
  402. {  
  403.     QString finishText = wizard()->buttonText(QWizard::FinishButton);  
  404.     finishText.remove('&');  
  405.     label->setText(tr("Click %1 to generate the class skeleton."// label的内容  
  406.                    .arg(finishText));  
  407. }  
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值