PDA

View Full Version : QTabWidget and .setTabsClosable(True)



prof.ebral
25th February 2010, 22:58
I do not quite understand why setting the TabsClosable as true does not automatically instantiate the close button closes the tabs. :confused:

I am a newbie, that is why I am here. I have looked over the QEvents class and even tried connecting my QTabWidget's tabCloseRequested signal, but I must be doing something incorrect.

How can I get my tabs to close when the buttons is pressed?

Rhayader
25th February 2010, 23:50
You can close close the tab by connecting the tabCloseRequested ( int index ) signal to a slot like
connect(tabWidget, SIGNAL(tabCloseRequested ( int )), this, slot(closeTab(int))).
The whole point I think is to validate the closing of the tab.
eg the following slot will close the clicked tab except if it is the first tab
void closeTab(int index)
{
if (!index)
tabWidget->removeTab(index);
}

prof.ebral
26th February 2010, 01:42
You can close close the tab by connecting the tabCloseRequested ( int index ) signal to a slot like
connect(tabWidget, SIGNAL(tabCloseRequested ( int )), this, slot(closeTab(int))).

I am not sure if you read that I had been trying to do that. I am using PyQt also, so there is going to be a difference in syntax.

When I try


self.connect(self.chatView, QtCore.SIGNAL('QtGui.QTabWidget.tabCloseRequested( int)'), self, QtCore.SLOT('closeTab(int)'))


I am told that the slot does not exist.

When I try


self.connect(self.chatView, QtCore.SIGNAL('QtGui.QTabWidget.tabCloseRequested( int)'), self, QtCore.SLOT(self.closeTab))

I am told that the slot argument is an instance method. And if I place the parenthesis behind it, (int), Python will try and call the instance right away.

When I try


self.connect(self, QtCore.SIGNAL('tabCloseRequested(index)'), self.closeTab)

or


self.connect(self.chatView, QtCore.SIGNAL('tabCloseRequested(index)'), self.closeTab)


nothing happens.

prof.ebral
26th February 2010, 04:36
Finally saw a working example:


QtCore.QObject.connect(self.chatView, QtCore.SIGNAL('tabCloseRequested(int)'), self.closeTab)


I was reading how I would need to go through QObject, but I wasn't sure how the computer need to be told that way. Thanks.