Results 1 to 2 of 2

Thread: [PyQt] QTabWidget resize problem

  1. #1
    Join Date
    Nov 2012
    Posts
    14
    Qt products
    Platforms
    Windows

    Default [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:

    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!

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: [PyQt] QTabWidget resize problem

    You could save and restore the splitter state: QSplitter::restoreState()

Similar Threads

  1. How can I resize QWidgets added to a QTabWidget
    By MorrisLiang in forum Newbie
    Replies: 1
    Last Post: 29th May 2010, 11:44
  2. [pyqt] Customizing QTabBar in QTabWidget..
    By pyqt123 in forum Qt Programming
    Replies: 0
    Last Post: 14th December 2009, 13:13
  3. Problem with PyQt 4.4.2 and Qt 4.4.0
    By tlam in forum Installation and Deployment
    Replies: 1
    Last Post: 6th August 2008, 16:34
  4. While loop problem in pyqt
    By neverlander in forum Qt Programming
    Replies: 6
    Last Post: 17th December 2007, 19:03
  5. QTabWidget->setCornerWidget() unexpected resize.
    By hickscorp in forum Qt Programming
    Replies: 7
    Last Post: 20th December 2006, 14:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.