Search code examples
qtqframeqvboxlayoutqwizardqwizardpage

How to add QFrame or QWidget as QWizardPage on QWidzard


I tried adding a frame/widget subclass on QWizard subclass but a wizard page is blank. I added QMainWindow subclass and it works fine.

QuickSetupWizard::QuickSetupWizard(QWidget *parent) :
    QWizard(parent),
    ui(new Ui::QuickSetupWizard)
{
   ui->setupUi(this);
   mpMainWindow = new MainWindow(); // QMainWindow subclass
   mpSource = new Source(); // Source is QFrame subclass
   QWizardPage *page = new QWizardPage;
   page->setTitle("Conclusion");
   QLabel *label = new QLabel("You are now successfully registered");
   label->setWordWrap(true);
   QVBoxLayout *layout = new QVBoxLayout;
   layout->addWidget(label);
   layout->addWidget(mpIrigMainWindow);
   page->setLayout(layout);
   addPage(page); // here able to add mainWindow as wizard page

   QWizardPage *page2 = new QWizardPage;
   QVBoxLayout *layout2 = new QVBoxLayout;
   layout2->addWidget(new QPushButton("xyz"));
   layout2->addWidget(mpSource);
   page2->setLayout(layout2);
   addPage(page2);
}

The second wizard page is only showing one push button. Frame is not there. Frame subclass has no problem that I have tested.


Solution

  • To add page on wizard addPage method is available. But what will be the items/widgets on page? So if I want to add QPushButton or QLabel on page, in documentation, code is available. We will create layout and add buttons and label on layout using addWidget function and finally set that layout tp QWizardPage. Similarly if I add one QPushButton, one QFrame or QWidget to layout using addWidget and set that layout on QWizardPage and add the page to QWizard, the page gets added to QWizard and QPushButton is also visible on page but QFrame/QWidget is not visible.

    I solved this by making QWizardPage subclass and in it I created QFrame with QWizardPage subclass as parent.

    SourceSelectionPage::SourceSelectionPage(QWidget *parent) :
    QWizardPage(parent),
    ui(new Ui::SourceSelectionPage)
    {
         ui->setupUi(this);
         mpSource = new Source(this); // QFrame get added to page
    }
    /////////////////////////////////////////////
    
    QuickSetupWizard::QuickSetupWizard(QWidget *parent) :
    QWizard(parent),
    ui(new Ui::QuickSetupWizard)
    {
        ui->setupUi(this);
        mpMainWindow = new MainWindow(); // QMainWindow subclass
        QWizardPage *page = new QWizardPage;
        page->setTitle("Conclusion");
        QLabel *label = new QLabel("You are now successfully registered");
        label->setWordWrap(true);
        QVBoxLayout *layout = new QVBoxLayout;
        layout->addWidget(label);
        layout->addWidget(mpIrigMainWindow);
        page->setLayout(layout);
        addPage(page); // here able to add mainWindow as wizard page
    
        SourceSelectionPage *page2 = new SourceSeleCtionPage();
        addPage(page2);
     }