为什么我无法在qt中显示堆叠的小部件?

时间:2016-05-25 09:24:08

标签: c++ qt

所以,我是Qt的新手。我的代码基于我对QStackedWidgets的理解。我的问题是我无法在索引0中显示小部件,即loginPage。当我运行代码时,显示的窗口是mainwindow.ui窗口。

centralWidget = new QWidget();

loginPage =     new Login;
registerPage =  new Register;
userPage =      new UserAccount;


stackWidget =   new QStackedWidget;

stackWidget->addWidget(loginPage);
stackWidget->addWidget(registerPage);
stackWidget->addWidget(userPage);

stackWidget->setFixedSize(500,340);


layout = new QVBoxLayout;

layout->addWidget(stackWidget);

setCurrentIndex(0);

setCentralWidget(centralWidget);

centralWidget->setLayout(layout);
stackWidget->move(0,0);
centralWidget->move(0,0);

setFixedSize(500,340);

centralWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

connect(loginPage,SIGNAL(changeCurrentIndex(int)),this,SLOT(setCurrentIndex(int)));
connect(registerPage,SIGNAL(changeCurrentIndex(int)),this,SLOT(setCurrentIndex(int)));
connect(userPage,SIGNAL(changeCurrentIndex(int)),this,SLOT(setCurrentIndex(int)));
ui->setupUi(this);

0 个答案:

没有答案