Example Qt programs using QStackedWidget?

0 like 0 dislike
7 views
I'm just learning qt and have decided to write a program window which is redrawn after clicking the button, i.e. when the program is installed, but I need that there was a cycle of transitions, and as I understand this class right for me, only in textbooks, it is practically not considered.
by | 7 views

4 Answers

0 like 0 dislike
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.
by
0 like 0 dislike
and what is there to consider? Take a widget which will be manipulated, and in the constructor write the following:
\r
class MainWidget::MainWidget(QWidget *parent = 0) : QWidget(parent) { ... stackedWidget = new QStackedWidget(this); stackedWidget->addWidget(someWidget1); stackedWidget->addWidget(someWidget2); ... setCentralWidget(stackedWidget); } 

\r
To switch widgets, you need to link for example here is a slot with any signal (clicked the button):
\r
\r
void MainWidget::buttonClicked() { stackedWidget->setCurrentIndex(index); } 

\r
Where index is the number of your widget.
by
0 like 0 dislike
Wrote at the conference on Maemo in Moscow programulku code here. There is a QStackedWidget, MB will fit.
by
0 like 0 dislike
My project: code.google.com/p/qcheckersmobile/
There is the main window uses it. Simple and, I think, is clear.
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
asked Sep 10, 2019 by makklovskiy
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Aug 12, 2019 by makklovskiy
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
1,119 users