在 QTabWidget (PyQT) 中添加删除的选项卡

发布于 2024-12-18 15:35:12 字数 1034 浏览 2 评论 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.

有什么建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

另类 2024-12-25 15:35:12

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

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)

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文