Jan-22-2019, 05:57 PM
I have a form that grows in height as the user provides information. Currently this occurs by dynamically adding tables and other widgets to a grid layout as the user enters information. The simplified starting point is something like this:
class UI(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setObjectName(_fromUtf8("Form"))
self.resize(800, 600)
self.gridLayout = QtGui.QGridLayout()
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.setLayout(self.gridLayout)Eventually, enough widgets may be added to the grid layout so the dialog content exceeds its height. Given this, I would like to implement the grid layout within the scroll area, but I can't seem to get things quite right:class UI(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
def setupUi(self):
self.setObjectName(_fromUtf8("Form"))
screen = QtGui.QDesktopWidget().screenGeometry()
self.resize(800, screen.height())
self.gridLayout = QtGui.QGridLayout()
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
w = QtGui.QWidget()
# w.setLayout(self.gridLayout)
s = QtGui.QScrollArea()
s.setMinimumHeight(screen.height())
s.setWidget(w)
s.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
s.setLayout(self.gridLayout)
l = QtGui.QVBoxLayout()
l.setContentsMargins(0, 0, 0, 0)
l.setSpacing(0)
l.addWidget(s)
# self.setLayout(self.gridLayout)
self.setLayout(l)Where am I going wrong? I have a scroll area and a scroll bar, but the contents that get added don't seem to be within the scrollable area? Any guidance is greatly appreciated.
