mainwindow.h
#ifndef TAB_H
#define TAB_H
#include <QtWidgets>
class Tab : public QWidget
{
public:
Tab(int id);
QStatusBar *sbar;
private:
};
#endif // TAB_H
mainwindow.cpp
#include "mainwindow.h"
#include "tab.h"
MainWindow::MainWindow()
{
tabs = new QTabWidget();
resize(800, 600);
connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
for(int i = 0; i < 20; i++)
{
tabs->addTab(new Tab(i), QString("%1").arg(i));
}
setCentralWidget(tabs);
}
MainWindow::~MainWindow()
{
}
void MainWindow::currentChanged(int)
{
Tab *thistab = static_cast<Tab*>(sender());
setStatusBar(new QStatusBar());
}
tab.h
#ifndef TAB_H
#define TAB_H
#include <QtWidgets>
class Tab : public QWidget
{
public:
Tab(int id);
QStatusBar *sbar;
private:
};
#endif // TAB_H
tab.cpp
#include "tab.h"
Tab::Tab(int id)
{
sbar = new QStatusBar();
QHBoxLayout hbl;
QLabel *ll = new QLabel("StatusBar tester: Tab number : #"+QString("%1").arg(id));
sbar->addWidget(new QLabel(QString("%1").arg(id)));
hbl.addWidget(ll);
setLayout(&hbl);
}
感谢您的耐心