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.
1 answer
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_; }; |
QStackedWidgetto 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