Help with PyQt4 tabwidget setup

Neil Wallace rowinggolfer*no_spam* at googlemail.com
Mon May 24 04:29:37 EDT 2010


On Fri, 21 May 2010 08:03:43 +0200, dpalmboom wrote:

> I am creating an application and I'm busy designing the main layout on
> the main window. What I would like to do is the following:
> 
> Create a QTabWidget with a QVBoxLayout already inside it and also a
> scrollbar inside it. When a user triggers a menu item, a QDockWidget
> must be created and inserted into the QVBoxLayout, but it must not
> stretch to the bottom of the QTabWidget. The QDockWidget must keep a set
> size in the QVBoxLayout. When the user triggers another menu item, the
> next QDockWidget must go above or below the existing QDockWidgets in the
> QVBoxLayout.
> 
> I currently have the following code for the QTabWidget:
> 
> class PaneTabWidget(PyQt4.QtGui.QTabWidget):
> 
> def __init__(self, tabs, parent=None):
> 
>     """
>     A tabwidget to go inside a Pane.
>     """
> 
>     super(PaneTabWidget, self).__init__(parent)
> 
>     for tab in tabs:
> 
>     if tab == "Properties":
>         self.propertiesBin()
>     elif tab == "Schedule":
>         self.scheduleBin()
>     elif tab == "Pricelist":
>         self.pricelistBin()
> 
>     def setLayoutAndScrollBar(self, page):
>         pass
> 
>     def addPanel(self, panel, type):
>         self.addTab(panel, type)
> 
>     def propertiesBin(self):
>         self.page = PyQt4.QtGui.QWidget()
>         self.addTab(self.page, "Properties")
>         self.setLayoutAndScrollBar(self.page)
> 
> Right now, the dockwidget gets put into a new tab in the tab widget, but
> I would like to put it into an existing QVBoxLayout. I currently have a
> blank QWidget as a "placeholder" page of the tabwidget.
> 
> If anyone can help me with this, it would be greatly appreciated.
> 
> Thanks


Hi,

not 100% sure what you are after, but perhaps a standard tabWidget, with 
a customised Scrollarea forming the panel is one way?

from PyQt4 import QtGui

class TabPane(QtGui.QScrollArea):
    def __init__(self, parent=None):
        super(TabPane, self).__init__(parent)
        frame = QtGui.QFrame(self)
        frame.setFixedSize(300,200)
        self.setWidget(frame)
        self.layout = QtGui.QVBoxLayout(frame) 
        
    def addDock(self, title):
        dw = QtGui.QDockWidget(title, self)
        self.layout.addWidget(dw)
        
if __name__ == "__main__":
    app = QtGui.QApplication([])

    tab_widget = QtGui.QTabWidget()
    for heading in ["Properties", "Schedule", "Pricelist"]:
        pane = TabPane()
        pane.addDock("Hello World")
        pane.addDock("Hello Galaxy")        
        pane.addDock("Hello Universe")        
        
        tab_widget.addTab(pane , heading)
    
    tab_widget.show()
    app.exec_()




More information about the Python-list mailing list