有关QStackedWidget问题
#include "widget.h"
#include "ui_widget.h"
#include<QWidget>
#include<QVBoxLayout>
#include<QComboBox>
#include<QStackedWidget>
#include<QLabel>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{ QWidget *firstPageWidget = new QWidget;
QWidget *secondPageWidget = new QWidget;
QWidget *thirdPageWidget = new QWidget;
QLabel *label=new QLabel(firstPageWidget);
label->setText("abc");
QStackedWidget *stackedWidget = new QStackedWidget;
stackedWidget->addWidget(firstPageWidget);
stackedWidget->addWidget(secondPageWidget);
stackedWidget->addWidget(thirdPageWidget);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(stackedWidget);
this->setLayout(layout);
QComboBox *pageComboBox = new QComboBox(this);
pageComboBox->addItem(tr("Page 1"));
pageComboBox->addItem(tr("Page 2"));
pageComboBox->addItem(tr("Page 3"));
connect(pageComboBox, SIGNAL(activated(int)),
stackedWidget, SLOT(setCurrentIndex(int)));
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}