0

我正面临 pyQT 的问题。所以我用设计器创建了一个图形界面,其中包含一个 QTabWidget。事情是我想在我的函数运行时隐藏和显示选项卡。我找到了一种解决方案,它包括删除所有选项卡并稍后添加它们。可以说我只有两个标签:

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

当我稍后尝试添加这个已删除的选项卡时,我的程序崩溃了。

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

这是我的错误信息:

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.

有什么建议么?

4

1 回答 1

2

您可以在主窗口对象或您拥有的任何小部件中声明您需要的所有选项卡:例如:

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

即使您尚未调用该addTab()方法,您也可以正常将小部件分配给您的选项卡。前任。:

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

必要时,您可以显示您的选项卡。前任。:

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

同样,您也可以从其索引号中再次删除它。前任。:

self.tabWidget.removeTab(3)

可以根据需要多次调用相同的选项卡。我认为这种方式非常干净和简单。如果这不符合您的需求,请告诉我。

于 2011-11-28T16:37:27.683 回答