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:

Qt Code:
  1. from PyQt4.QtCore import *
  2. from PyQt4.QtGui import *
  3.  
  4. class HidingTabWidget(QTabWidget):
  5. def __init__(self, parent):
  6. super(QTabWidget, self).__init__(parent)
  7. self.show_tab = True
  8. self.max_height = 1000000
  9.  
  10. def OnHideShow(self, event):
  11. self.show_tab = not self.show_tab
  12. if self.show_tab:
  13. self.setFixedHeight(self.h)
  14. self.setMinimumHeight(2*self.tb_h)
  15. self.setMaximumHeight(self.max_height)
  16. else:
  17. self.h = self.height()
  18. self.setFixedHeight(self.tb_h)
  19. print self.height()
  20.  
  21. def AddTab(self, widget, label):
  22. self.addTab(widget, label)
  23. index = self.indexOf(widget)
  24. self.tabBar().setTabText(index, label)
  25. button = QPushButton(self)
  26. button.setMaximumSize(16,16)
  27. self.tabBar().setTabButton(index, QTabBar.RightSide, button)
  28. button.clicked.connect(self.OnHideShow)
  29. self.tb_h = self.tabBar().height()-7
  30. self.setMinimumHeight(2*self.tb_h)
  31. self.setMaximumHeight(self.max_height)
  32.  
  33.  
  34. class Panel(QWidget):
  35. def __init__(self, parent=None):
  36. QWidget.__init__(self)
  37.  
  38. l = QVBoxLayout(self)
  39. splitter = QSplitter(self)
  40. splitter.setOrientation(Qt.Vertical)
  41. frame1 = QFrame(splitter)
  42. frame1.setMinimumHeight(50)
  43. tab_table = HidingTabWidget(splitter)
  44.  
  45. l.addWidget(splitter)
  46. tab_table.AddTab(QTableView(), "Table")
  47.  
  48. self.setLayout(l)
  49. self.resize(600,400)
  50.  
  51. if __name__ == "__main__" :
  52. import sys, os
  53.  
  54. a = QApplication(sys.argv)
  55. dia = Panel()
  56. dia.show()
  57. a.exec_()
To copy to clipboard, switch view to plain text mode 

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!