[PyQt] QTabWidget resize problem
Hi everyone,
I'm trying to develop a custom QtabWidget which can auto-hide by clicking on a button placed in the widget tab. Here is a sample code:
Code:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
def __init__(self, parent):
self.show_tab = True
self.max_height = 1000000
def OnHideShow(self, event):
self.show_tab = not self.show_tab
if self.show_tab:
self.setFixedHeight(self.h)
self.setMinimumHeight(2*self.tb_h)
self.setMaximumHeight(self.max_height)
else:
self.h = self.height()
self.setFixedHeight(self.tb_h)
print self.height()
def AddTab(self, widget, label):
self.addTab(widget, label)
index = self.indexOf(widget)
self.tabBar().setTabText(index, label)
button.setMaximumSize(16,16)
self.
tabBar().
setTabButton(index,
QTabBar.
RightSide, button
) button.clicked.connect(self.OnHideShow)
self.tb_h = self.tabBar().height()-7
self.setMinimumHeight(2*self.tb_h)
self.setMaximumHeight(self.max_height)
def __init__(self, parent=None):
splitter.setOrientation(Qt.Vertical)
frame1.setMinimumHeight(50)
tab_table = HidingTabWidget(splitter)
l.addWidget(splitter)
self.setLayout(l)
self.resize(600,400)
if __name__ == "__main__" :
import sys, os
dia = Panel()
dia.show()
a.exec_()
If you click on the tab button, the widget collapses as I expect and its size cannot be changed. If you then re-click it, the widget original size is restored. The problem arises if I try to resize the widget when it is collapsed. If you try that and then re-click the tab button, the height of the widget is set to its minimum value, even if self.height() returns the correct height value. Is there anything I am missing?
Thanks in advance for your help!
Re: [PyQt] QTabWidget resize problem
You could save and restore the splitter state: QSplitter::restoreState()