点击两个按钮,可以切换tab的内容。
效果图:
:
#include “security360.h”
 #include<QPushButton>
 #include<QHBoxLayout>
 #include<QtGui>
 #include<QSplitter> 
 #include<QLabel>
 security360::security360(QWidget *parent)
 : QMainWindow(parent)
 {
 ui.setupUi(this);
 //button
 QPushButton *button1 = new QPushButton(“&First”,this);
 QPushButton *button2 = new QPushButton(“&Second”,this);
 
 button1->move(0, 20);
 button2->move(0,100);
 
 //lable
 
 QLabel *label1 = new QLabel(“sssss”);
 QLabel *label2 = new QLabel(“DDDDD”);
 //tab
 
 tab = new QTabWidget;
 tab->addTab(label1,”ddd”);
 //tab->addTab(label2, “ssss”);
 //tab->setTabsClosable(true);
 tab->setStyleSheet(“backgroud-color:#f0ffaaf”);
 
 //layout
 QVBoxLayout * layout = new QVBoxLayout;
 QHBoxLayout*mainLayout = new QHBoxLayout;
 /*
 //splitter
 QSplitter *litter = new QSplitter(Qt::Vertical, 0);
 litter->setLayout(layout);
*/
 layout->addWidget(button1);
 layout->addWidget(button2);
 
 mainLayout->addLayout(layout);
 mainLayout->addWidget(tab);
 QWidget *widget = new QWidget();
 this->setCentralWidget(widget);
 widget->setLayout(mainLayout);
 setWindowTitle(“ALBUM”);
 
 connect(button1,SIGNAL(clicked()),this,SLOT(change()));
 connect(button2, SIGNAL(clicked()), this, SLOT(changeSec()));
}
 security360::~security360()
 {
 }
 void security360::change(){
 tab->removeTab(0);
 qDebug() << “CHANGE”;
 QLabel *LA = new QLabel(“chang the first tab”);
 tab->addTab(LA,”first”);
 }
 void security360::changeSec(){
 tab->removeTab(0);
 qDebug() << “CHANGE”;
 QLabel *LA = new QLabel(“chang the second tab”);
 tab->addTab(LA, “second”);
 } 
备注::
