Force Qt/PyQt/PySide QTabWidget to resize to active tab

前端 未结 1 1489
清歌不尽
清歌不尽 2021-01-16 04:24

I have a QTabWidget working correctly except that it doesn\'t re-size how I would expect it.

There are 2 tabs in the widget. Each has a QVBoxLayout with widgets in

相关标签:
1条回答
  • 2021-01-16 04:50

    This should do the trick; change the size policy depending on which tab is active.

    def __init__(self):
        super(Widget, self).__init__()
        self.setupUi(self)
        self.tabWidget_2.currentChanged.connect(self.updateSizes)
    
    def updateSizes(self):
        for i in range(self.tabWidget_2.count()):
            self.tabWidget_2.widget(i).setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
    
        current = self.tabWidget_2.currentWidget()
        current.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
    
    0 讨论(0)
提交回复
热议问题