How to set QScrollArea with stretch
-
Hello, I am trying to create a sidebar for my interface, but I am having some issues. I have a few QPushButtons in a QVBoxLayout. These should then be followed by a QScrollArea, which is then followed by another QVBoxLayout containing some other widgets (see picture). The goal is that the QScrollArea is small so e.g. it only shows lie 4 widgets(lets say QLabels) and if it contains more of these, you have to scroll down to see the other labels. But right now, if I add more labels, the whole ScrollArea widget (and the window size) just gets bigger and the lower part of my window disappears below the taskbar.
How can i stop the QScrollArea from getting this big?
I tried setting the stretch but it did not have any influence, I also don't want to set a maximumsize for the scrollarea because i have heard that is bad practice because on bigger screens than mine the widget will not scale according to the screen size increase.

-
Did you set up the scroll area correctly, that is, using QScrollArea::setWidget() to set a viewport widget with a vertical layout containing the widgets to be scrolled?
-
I believe it is correct, I did the following:
self.frame=QFrame()
self.frame.setLayout(QVBoxLayout())
self.ScrollArea=QScrollArea()
self.ScrollArea.setWidget(self.frame)
self.ScrollArea.setWidgetResizable(True)
#I also tried it without the line above but didn't work either.
for i in range(10):
| self.frame.layout().addWidget(QLabel)#or any widget
self.SideBar.addWidget(self.ScrollArea)
Is there anything I could do differently? -
Other than toying around with the self.ScrollArea.setWidgetResizable(), setting no, this looks correct.