I have a QScrollArea
with a QHBoxLayout
and when I add a lot of widgets to the layout, they get condensed into a small size instead of adding a scroll bar as I intended, as the image below shows:
Here's the code I'm using:
from PyQt5.QtWidgets import QGroupBox, QHBoxLayout, QLabel, QVBoxLayout, QScrollArea
class LayerParamsBox(QGroupBox):
def __init__(self):
super().__init__()
self.setTitle("Layer Parameters")
self.setLayout(QHBoxLayout())
self.scroll_area = QScrollArea()
self.scroll_area.verticalScrollBar().setEnabled(False)
self.scroll_area.setLayout(QHBoxLayout())
self.layout().addWidget(self.scroll_area)
test = Test("test test")
for i in range(30):
self.add_layer(test, i)
def add_layer(self, layer, n):
inner_box = QGroupBox()
self.scroll_area.layout().addWidget(inner_box)
inner_box.setLayout(QVBoxLayout())
inner_box.setTitle(f"Layer {n}")
label = QLabel(layer.type_name)
inner_box.layout().addWidget(label)
class Test:
def __init__(self, name):
self.type_name = name
What I want to do is, I want the inner boxes to not get resized and be as large as necessary to show the labels within it, and if I add more inner boxes than the window can fit then a horizontal scrollbar should show up, how can I achieve this?