0
votes

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?

1
Actually it is not clear enough. Why are you "removing all the tabs and adding them later"? Why don't you declare all the tabs you need and call them when you want and remove them from index when don't want them anymore? - jonathan.hepp
In the first place I just wanted to hide some tabs and show them at a precise moment of my function. As there is no hide/show methods for tabs, I found that solution that removes the tabs I created in my .ui (without deleting them). - NicoCati

1 Answers

2
votes

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.