0
votes

I am trying to generate a Dialog with a stacked layout of GridLayout (of CheckBox's) and HLayout. Well, I did. But my grid got big (my HLayout is fine) but now I want a ScrollArea so as to not take up too much real estate. I have tried the following code .... and it generates a scroll view, but the size of the scroll view is the size of a button (the first ofc) in the HLayout. I want the scroll view to be the width of the Dialog, which nominally would be the minimum width of the HLayout. Additionally adding the scroll_view and scroll_viewWidget cause a QLayout exception to be raised, QLayout::addChildLayout: layout "" already has a parent. Any idea's?

class checkboxDialog(QtGui.QDialog) : 

def __init__(self, headers, name) :
    super(checkboxDialog, self).__init__()

    self.checkerLayout = QtGui.QVBoxLayout()
    self.checkerLayout.setMargin(1)
    self.checkerLayout.setSpacing(2)

    self.scroll_view = QtGui.QScrollArea(self)
    self.scroll_view.setWidgetResizable(True)

    self.scroll_viewWidget = QtGui.QWidget()
    self.scroll_viewWidget.setGeometry(QtCore.QRect(0, 0, 600, 400))
    self.scroll_view.setWidget(self.scroll_viewWidget)        

    self.checkerHlayout = QtGui.QHBoxLayout(self.scroll_viewWidget)

    checksLayout = QtGui.QGridLayout()
    checksLayout.setColumnStretch(90,7)
    checksLayout.setMargin(1)
    checksLayout.setSpacing(2)      
    self.cbList = []
    index  = 0
    for row_index in range(90):
        for column_index in range(7):
            if index > len(headers)-1 : break
            checkbox = QtGui.QCheckBox(headers[index][0:8], self)
            checkbox.setToolTip("Chanel = {}".format(headers[index]))
            self.cbList.append(checkbox)
            # Hide the Phase channels for now ... not sure I shoudl even build the CheckBoxes
            # But if I dont then the len(cbList) < len(data[0])
            if headers[index][-1] == 'p' :
                checkbox.hide()
            checksLayout.addWidget(checkbox, row_index, column_index)
            index += 1

    self.checkerHlayout.addLayout(checksLayout)

    self.buttonLayout = QtGui.QHBoxLayout()
    self.buttonLayout.setMargin(1)
    self.buttonLayout.setSpacing(2)

    applyButton = QtGui.QPushButton("Apply")
    nextButton = QtGui.QPushButton("Next")
    nextAllButton = QtGui.QPushButton("NextAll")
    prevButton = QtGui.QPushButton("Prev")
    prevAllButton = QtGui.QPushButton("PrevAll")
    clearButton = QtGui.QPushButton("Clear")

    self.buttonLayout.addWidget(applyButton)        
    self.buttonLayout.addWidget(nextButton)
    self.buttonLayout.addWidget(nextAllButton)
    self.buttonLayout.addWidget(prevButton)
    self.buttonLayout.addWidget(prevAllButton)
    self.buttonLayout.addWidget(clearButton)

    self.checkerLayout.addLayout(self.checkerHlayout)
    self.checkerLayout.addLayout(self.buttonLayout)
    self.setLayout(self.checkerLayout)

    self.setObjectName(name)
    self.setWindowTitle(name)

    self.connect(applyButton, QtCore.SIGNAL('clicked()'), self.checked)
    self.connect(nextButton, QtCore.SIGNAL('clicked()'), self.next_chn)
    self.connect(nextAllButton, QtCore.SIGNAL('clicked()'), self.next_chnAll)
    self.connect(prevButton, QtCore.SIGNAL('clicked()'), self.prev_chn)
    self.connect(prevAllButton, QtCore.SIGNAL('clicked()'), self.prev_chnAll)
    self.connect(clearButton, QtCore.SIGNAL('clicked()'), self.clear_chn)
1

1 Answers

1
votes

I think this is what you wanted:

    self.w2 = QtGui.QWidget(self)
    self.w2.setLayout(self.buttonLayout)
    self.checkerLayout.addWidget(self.w2)
    self.checkerLayout.addWidget(self.scroll_view)
    self.setLayout(self.checkerLayout)

(replacing the block with addLayout statements)