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 :
我正面临着pyQT的问题。所以我用designer创建了一个图形界面,其中包含一个QTabWidget。我希望在函数运行时隐藏和显示选项卡。我找到了一种解决方案,即删除所有选项卡,然后添加它们。假设我只有两个标签:
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 个解决方案
#1
2
You can declare all the tabs you need in your mainwindow object or whatever widget you have: Ex.:
您可以在主窗口对象或任何您拥有的小部件中声明所需的所有选项卡: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.:
即使您还没有调用addTab()方法,也可以正常地将小部件分配给选项卡。例:
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.
可以任意多次调用同一个选项卡。我觉得这种方式很干净简单。如果不适合你的需要,请告诉我。
#1
2
You can declare all the tabs you need in your mainwindow object or whatever widget you have: Ex.:
您可以在主窗口对象或任何您拥有的小部件中声明所需的所有选项卡: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.:
即使您还没有调用addTab()方法,也可以正常地将小部件分配给选项卡。例:
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.
可以任意多次调用同一个选项卡。我觉得这种方式很干净简单。如果不适合你的需要,请告诉我。