NicoCati
NicoCati

Reputation: 557

Adding removed tabs in QTabWidget (PyQT)

I'm facing an issue with pyQT. So I created a graphical interface with designer, containing a QTabWidget. The things is I would like to hide and show tabs when my function is running. I found one solution that consists in removing all the tabs and adding them later. Lets say I only have two tabs :

removedTab = self._application.getAlgorithmGUI().getWidget('tabWidget_Verification').widget(1)
self._application.getAlgorithmGUI().getWidget( 'tabWidget_Verification' ).removeTab( 1 )

And when I try later to add this removed tab, my program crashes.

self._application.getAlgorithmGUI().getWidget( 'tabWidget_Verification' ).addTab(removedTab,QString.fromUtf8("TabRemoved"))

This is my error message :

QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread
QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread
QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread
QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread
<unknown>: Fatal IO error 11 (Ressource temporairement non disponible) on X server :0.0.

Any suggestions?

Upvotes: 0

Views: 4963

Answers (1)

jonathan.hepp
jonathan.hepp

Reputation: 1653

You can declare all the tabs you need in your mainwindow object or whatever widget you have: Ex.:

self.tab = QtGui.QWidget()
self.tab.setObjectName(_fromUtf8("tab"))

And you can assign the widgets to your tabs normally even if you didn't call the addTab() method yet. Ex.:

self.lineEdit = QtGui.QLineEdit(self.tab)

Whenever it is necessary, you can show your tab. Ex.:

self.tabWidget.addTab(self.tab, "Label")

And on the same way, you can also remove it again, from its index number. Ex.:

self.tabWidget.removeTab(3)

The same tab can be called again as many times as you want. I think this way is quite clean and simple. If this doesn't fit in your needs please let me know.

Upvotes: 2

Related Questions