Python PyQT Qtabwidget隐藏并关闭某些选项卡
是否可以隐藏和关闭Qtabwidget中的某个选项卡?我有5个选项卡,其中两个是在使用我的软件时生成的绘图。首先,我想在开始时隐藏这两个绘图,其次,我想在生成后使它们可以关闭。这可能吗?使用Python PyQT Qtabwidget隐藏并关闭某些选项卡,python,tabs,pyqt,Python,Tabs,Pyqt,是否可以隐藏和关闭Qtabwidget中的某个选项卡?我有5个选项卡,其中两个是在使用我的软件时生成的绘图。首先,我想在开始时隐藏这两个绘图,其次,我想在生成后使它们可以关闭。这可能吗?使用self.setTabsClosable(True)所有选项卡都将可关闭 谢谢 import sys from PyQt4 import QtGui class QCustomTabWidget (QtGui.QTabWidget): def __init__ (self, parent = Non
self.setTabsClosable(True)
所有选项卡都将可关闭
谢谢
import sys
from PyQt4 import QtGui
class QCustomTabWidget (QtGui.QTabWidget):
def __init__ (self, parent = None):
super(QCustomTabWidget, self).__init__(parent)
self.setTabsClosable(True)
self.tabCloseRequested.connect(self.closeTab)
for i in range(1, 10):
self.addTab(QtGui.QWidget(), 'Tab %d' % i)
def closeTab (self, currentIndex):
currentQWidget = self.widget(currentIndex)
currentQWidget.deleteLater()
self.removeTab(currentIndex)
myQApplication = QtGui.QApplication([])
myQCustomTabWidget = QCustomTabWidget()
myQCustomTabWidget.show()
sys.exit(myQApplication.exec_())
可以删除不应关闭的选项卡的“关闭”按钮。这是通过使用
qtabar
的功能setTabButton
完成的,如下所示:
QtGui.QTabWidget.tabBar().setTabButton(0, QtGui.QTabBar.RightSide,None)
在这里,我们将第一个选项卡的按钮设置为None
使用相同的功能,您还可以在选项卡上创建自己的关闭按钮(并删除self.setTabsClosable(True)
)