I have a QVBoxLayout which has a QSCrollArea and with addStretch() added to its end.
QScrollArea here gets to use only half of the available space eventhough there is free space below,, currently occupied by addStretch.
If contents of the QScrollArea are large enough, I want QScrollArea to expand to all the available space. When QScrollArea's contents are smaller, I want QScrollArea to shrink to that size, with rest of the available space used by addStetch.
However, currently, for small QScrollArea this works but when QScrollArea's contents are larger, it only expands to half of the available space.
I tried setting various Size Policies for the QScrollArea and the underlying scrolling widget but nothing works.
What's the trick to get this sorted?
Here's a snipped of my code [in Python but answers in C++ are very welcome]:
# My setup
self.layout = QVBoxLayout()
self.setLayout(self.layout)
scrollArea = QScrollArea()
self.layout.addWidget(scrollArea)
scrollArea.setWidgetResizable(True)
scrollArea.setEnabled(True)
self.scrollWidget = QWidget()
self.scrollLayout = QVBoxLayout()
self.scrollWidget.setLayout(self.scrollLayout)
scrollArea.setWidget(self.scrollWidget)
# Now what I do is, I add bunch of widgets inside the self.scrollLayout
# and in the end, I perform a self.layout.addStretch() to push them up (verticle Alignment does same)
# Maximum height QScrollArea (scrollArea) gets is stuck at around 50% although I want to take all the space if necessary
I added ALL possible setSizePolicy(..) options
scrollArea.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
# and ALL others. None works. addStretch() still takes 50% minimum space and gets even more if QScrollArea's contents are smaller.