Close button only for some tabs in Qt

后端 未结 7 1956
天命终不由人
天命终不由人 2021-02-05 05:22

I am using Qt for an assignment I have for college, and I want to use QTabWidget to display a chat window much like Pidgin\'s. I want to make the \"group chat\" tab

7条回答
  •  粉色の甜心
    2021-02-05 06:06

    I guess you can handle the tabCloseRequest signal and decide whether u'll close a given tab or not

    http://doc.qt.io/archives/4.6/qtabwidget.html#tabCloseRequested

    Edit: I created a small example to check it out. My example is a simple QtGui application with a mainwindow that has a tabwidget. I then added the tabCloseRequested slot. Here is the code

    void MainWindow::on_tabWidget_tabCloseRequested(int index)
    {
       if(someCondition){
           return;
       } else if(anotherCondition){
           ui->tabWidget->removeTab(index);
       }
    }
    

    From this example only tabs where the condition doesn't apply will be closed.

提交回复
热议问题