qt中的TabWidget应用程序框架

 
  
 
  
#include 
 
  
//-----------------------------------------------------------------------  1
//整体基于  
class MainWindow : public QMainWindow
{

private slots:   
    void open();
    void close();   
    void tabCloseRequested(int index); 
}

//-------------------------------------------------------------------------2
void MainWindow::tabCloseRequested(int index)
 {
  QString tabCaption = ui->tabWidget->tabText(index);
  if(QMessageBox::question(this, tr("Message"), tr("是否要关闭窗口:") + tabCaption, QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
    delete ui->tabWidget->widget(index);//关闭页签并释放掉对应的widget控件对象
 }

//------------------------------------------------------------------------ 3
//构造函数中实现

     delete ui->tab;  //删除tabWidget上默认带有的两个页签
     delete ui->tab_2;
 
  
 
  
                     //新建第一个页面的部件
     Dialog222 *label = new Dialog222();      
     QIcon icon1(":/image/m1.ico");
     ui->tabWidget->addTab(label, icon1, "  解 压");
 
  
      //点击页签上的叉号触发
 
  
     connect(ui->tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(tabCloseRequested(int)));
 
  
//----------------------------------------------------------------------  4
 
  
void MainWindow::open()
{
 
  
    ui->tabWidget->removeTab(0);
    Dialog222 *label = new Dialog222();
    //向QTabWidget中添加第一个页面
    QIcon icon1(":/image/m1.ico");
    ui->tabWidget->addTab(label, icon1, "   压");
}

 
  
 
  
 
 

你可能感兴趣的:(Qt,Creator)