tags:

views:

288

answers:

2

Hello,

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 always open and impossible to close and the rest of the "private channel" tabs closable.

QTabWidget's setTabsClosable(bool) is not helping ...

any ideas?

ty

+1  A: 

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

http://doc.qt.nokia.com/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.

thelinuxer
no, it will not help, because when signal received, event is already going to be done, and signal can't do anything.
Max
I added tabCloseRequest slot in my response to clarify how it can be used.
thelinuxer
A: 

You should reimplement your widget's event(Event *e) method, check the type of e, find out CloseEvents, and call parent class's event when you can allow tab to close, or e->ignore() when you do not want it.

Note, then you must parent's event() handle othr events, so do not accept(), reject() or forget them Ж)

Max