【发布时间】:2019-12-30 21:30:38
【问题描述】:
我在看 2 年前提出的这个问题:Make every tab the same width and also expandable
解决方案正是我正在寻找的,只是它对我不起作用。我认为我的代码中缺少一些元素。
我使用 QtDesigner 来设计窗口。我导入创建的.py。此文件包含我想要调整大小并使用所有可用宽度的QTabWidget。它被插入到 HBoxLayout 中,旁边有一个 Frame。
然后我在controller_file.py中进行如下操作:
我覆盖了TabBar 类:
class tabBar(QTabBar):
def __init__(self, parent=None):
QTabBar.__init__(self, parent)
def tabSizeHint(self, index):
size = QTabBar.tabSizeHint(self, index)
w = int(self.width()/self.count())
return QSize(w, size.height())
然后,我在controller_file.py的__init__中.setTabBar(tabBar())到QTabWidget:
class flex_ctrl(QObject):
def __init__(self, model, view, parent=None):
super().__init__(parent)
self._model = model
self._view = view
self.is_save = True
self.file_name = ''
self._view.graph_tot_tab.setTabBar(tabBar())
self._get_file_menu()
self._connect_signals()
self.view.installEventFilter(self)
问题是当我这样做时,栏消失了。我无法在标签之间切换:
变成这样:
你能帮帮我吗?
P.S:抱歉,如果不给出整个代码,我无法给出一个完全可重现的问题示例。我没有找到如何重现这个“错误”
【问题讨论】:
标签: python pyqt5 qtabwidget qtabbar