0
我以Qt開頭。以前,我使用了Java Swing,我通過Card Layout實現了這一點。我有MainWindow,Login Widget和Dashboard Widget。如何從自定義窗口小部件類更改中央窗口小部件?
MainWindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// set login screen on startup
QWidget *login = new Login(this);
setCentralWidget(login);
}
Login.cpp
#include "login.h"
#include "ui_login.h"
Login::Login(QWidget *parent) :
QWidget(parent),
ui(new Ui::Login)
{
ui->setupUi(this);
}
Login::~Login()
{
delete ui;
}
void Login::on_loginButton_clicked()
{
// some logic
// here I want to create Dashboard widget in central widget
// but method setCentralWidget() can't be called from here
}