大家好,我是使用 Qt 编程的新手,我想使用QStackedLayout
. 我已经用 Qt Creator 设计了一些小部件,将它们添加到QStackedLayout
并设置到主小部件。但是现在我想使用该setCurrentIndex
方法使用添加的小部件内的按钮来更改小部件。现在我必须使用该connect
功能,但在主小部件类中,我无法从其他小部件访问组件来连接它们。那么我该怎么做呢?
#include "mainwindowwidget.h"
#include "ui_mainwindowwidget.h"
MainWindowWidget::MainWindowWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::MainWindowWidget)
{
qApp->setStyleSheet("MainWindowWidget {background-color : red}");
//initializing widgets
this->mainWidget_ = new MainWidget;
this->createGameWidget_ = new CreateGameWidget;
this->widgets_ = new QStackedLayout;
//adding widgets to QstackedLayout
this->widgets_->addWidget(this->mainWidget_);
this->widgets_->addWidget(this->createGameWidget_);
this->setLayout(this->widgets_);
this->showFullScreen();
// I would like to connect the qstackedlayout
// = widgets_ with a button placed in mainwidget_
ui->setupUi(this);
}
MainWindowWidget::~MainWindowWidget()
{
delete ui;
}