I struggled for a while to get a QGroupBox that was able to be scrolled. I eventaully came up with something, but it didn't have the interface of a QGroupBox.. So I decided to challenge myself to come up with one that had the same interface. Here's what I came up with:

class QScrollVGroupBox(QVGroupBox):
    def __init__(self, *args):

        # initialize the main object
        apply( QVGroupBox.__init__, (self,) + args )

        # must store this in self, otherwise gets deleted.
        self.s = QScrollView(self.parentWidget())

        # reparent to make groupbox child of scroller
        self.reparent( self.s.viewport(), QPoint(0,0) )

        # give control of the group box to the scroller
        self.s.addChild(self)

        # create a layout manager, so that it will take up the entire
        # space. Otehrwise, it only takes up a "default size"
        layout = QVBoxLayout( self.s.viewport() )

        # Add the groupbox to the layout manager of the viewport.
        layout.addWidget( self )

    # returns the proper widget for showing/adding to containers
    def getScrollWidget(self):
        return self.s

Note that when you use this, in order to add it to another widget, you have to use the getScrollWidget() call to get the correct widget.. Like this:

    import sys

    app = QApplication( sys.argv )

    c = QScrollVGroupBox(None)
    c.setColumns(2)

    # add some items
    for x in range(1,50):
        QLabel( "test%d" % x, c )
        QLineEdit(c)

    c.getScrollWidget().show()

    app.setMainWidget( c.getScrollWidget() )

    app.exec_loop()

ScrollableGroupBox (last edited 2005-05-16 23:39:15 by JohnSutherland)