Well, give you a piece of my code, again, this is not the entire programme, and is the piece where I use QStackedWidget.
\r
\r
MainWidget::MainWidget(QWidget *parent = 0) : QWidget(parent) { // Widget to exercise "mosaic". mosaicWidget = new MosaicWidget(this); // Widget for exercises "card". cardWidget = new CardWidget(this); // Widget to practice "writing". cardWidget = new CardWidget(this); // Connect the signal end of exercise with a slot the following settings of the widget connect(mosaicWidget, SIGNAL(finished()), this, SLOT(setupNextLesson())); stackedWidget->addWidget(mosaicWidget); .. // Similarly for all other } MainWidget::setupNextLesson() { // Get a random index from 0 to 2 int randomIndex = qrand() % 3; // A specific custom widget to display switch(randomIndex) 0 : mosaicWidget->setup(); break(); 1 : cardWidget->setup(); break(); 2 : writeWidget->setup(); break(); // Directly activate the desired widget stackedWidget->setCurrentIndex(randomIndex); updateStatusBar(); }
p.s. I changed the example for simplicity, in real life, all my widgets are inherited from one abstract class, which had resulted in General methods, the result the code became smaller and more readable.