간단한 마법사 예제
간단한 마법사 예제에서는 QWizardPage 의 인스턴스 3개와 QWizard 의 인스턴스 1개를 사용하여 선형 3페이지 등록 마법사를 만드는 방법을 설명합니다.
소개 페이지
소개 페이지는 QWizardPage 이 생성되고 제목이 "소개"로 설정된 createIntroPage()
함수를 사용하여 생성됩니다. QLabel 는 page
의 설명을 저장하는 데 사용됩니다. QVBoxLayout 는 label
을 저장하는 데 사용됩니다. 이 page
는 createIntroPage()
함수가 호출될 때 반환됩니다.
QWizardPage *createIntroPage() { QWizardPage *page = new QWizardPage; page->setTitle("Introduction"); QLabel *label = new QLabel("This wizard will help you register your copy " "of Super Product Two."); label->setWordWrap(true); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(label); page->setLayout(layout); return page; }
등록 페이지
등록 페이지는 createRegistrationPage()
함수를 사용하여 생성됩니다. QLineEdit 객체는 사용자가 이름과 이메일 주소를 입력할 수 있도록 하는 데 사용됩니다. QGridLayout 객체는 QLabel 및 QLineEdit 객체를 보유하는 데 사용됩니다.
QWizardPage *createRegistrationPage() { QWizardPage *page = new QWizardPage; page->setTitle("Registration"); page->setSubTitle("Please fill both fields."); QLabel *nameLabel = new QLabel("Name:"); QLineEdit *nameLineEdit = new QLineEdit; QLabel *emailLabel = new QLabel("Email address:"); QLineEdit *emailLineEdit = new QLineEdit; QGridLayout *layout = new QGridLayout; layout->addWidget(nameLabel, 0, 0); layout->addWidget(nameLineEdit, 0, 1); layout->addWidget(emailLabel, 1, 0); layout->addWidget(emailLineEdit, 1, 1); page->setLayout(layout); return page; }
결론 페이지
결론 페이지는 createConclusionPage()
함수에서 생성됩니다. 이 함수의 콘텐츠는 createIntroPage()
와 유사합니다. QLabel 은 등록 프로세스가 성공적으로 완료되었음을 사용자에게 알리는 데 사용됩니다.
QWizardPage *createConclusionPage() { QWizardPage *page = new QWizardPage; page->setTitle("Conclusion"); QLabel *label = new QLabel("You are now successfully registered. Have a " "nice day!"); label->setWordWrap(true); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(label); page->setLayout(layout); return page; }
main()
함수
main()
함수는 QWizard 객체 wizard
를 인스턴스화하고 여기에 3개의 QWizardPage 객체를 모두 추가합니다. wizard
창 제목은 "사소한 마법사"로 설정되고 show()
함수가 호출되어 표시됩니다.
int main(int argc, char *argv[]) { QApplication app(argc, argv); #ifndef QT_NO_TRANSLATION QString translatorFileName = QLatin1String("qtbase_"); translatorFileName += QLocale::system().name(); QTranslator *translator = new QTranslator(&app); if (translator->load(translatorFileName, QLibraryInfo::path(QLibraryInfo::TranslationsPath))) app.installTranslator(translator); #endif QWizard wizard; wizard.addPage(createIntroPage()); wizard.addPage(createRegistrationPage()); wizard.addPage(createConclusionPage()); wizard.setWindowTitle("Trivial Wizard"); wizard.show(); return app.exec(); }
QWizard 및 라이선스 마법사 예시도참조하세요 .
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.