Using Qt Designer, I added a QStackedWidget and two pages to the window. How should I do this to add buttons and other widgets to these pages? (I just started using this Designer). If you do not fully understand what I want to say, I can supplement the text with details.

  • 2
    It seems to me that everything is intuitively clear, you change the size of the QStackedWidget to the right one, initially there are 2 pages, you throw in the necessary elements there, this is the first one, then right click on the stack and click the next page, then the next one can be added through the context menu, or delete there. - Vyacheslav Savchenko
  • I mean how then to manipulate them? How then when you press the button to change the widget? - Astemir Tsechoev
  • one
    Change CurrentIndex - Vyacheslav Savchenko

1 answer 1

I will give a minimal example:

 class Foo : public QWidget { Q_OBJECT public: Foo(QWidget* parent = 0) : QWidget(parent), stw_(new QStackedWidget(this)) { QVBoxLayout* lo = new QVBoxLayout(); QPushButton* btn = new QPushButton(this); lo->addWidget(stw_); lo->addWidget(btn); this->setLayout(lo); connect(btn, SIGNAL(clicked()), this, SLOT(slotChangePage())); addPages(); } private slots: void slotChangePage() { int index = stw_->currentIndex() + 1; if (index >= stw_->count()) { index = 0; } stw_->setCurrentIndex(index); } private: void addPages() { // Здесь разместить код вставки страниц в QStackedWidget, // например, используя QStackedWidget::addWidget(QWidget*) } private: QStackedWidget* stw_; };