Custom QScrollArea
Solution 1:
you can use "gridlayout" or set limit for your items with use "setMinimumSize" below like this example
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
class main(QMainWindow):
def __init__(self):
super().__init__()
self.scroll = QScrollArea()
self.scroll.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn)
self.widget = QWidget()
self.scroll.setWidgetResizable(True)
# => grid set
self.grid = QGridLayout(self.widget)
self.grid.setContentsMargins(10,40,10,20)
self.grid.setHorizontalSpacing(20)
self.grid.setVerticalSpacing(10)
for i in range(6):
for j in range(3):
if i % 2 == 1:
self.grid.addWidget(QLabel("DateTime => 01.19.2022 | $400 | ROLL"), i,j, 1,3)
break
else:
self.label = QLabel("9")
self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.label.setStyleSheet("background-color: red;")
# => item set minimum size !
self.label.setMinimumSize(120,120)
self.grid.addWidget(self.label, i, j, 1,1)
self.scroll.setWidget(self.widget)
self.setCentralWidget(self.scroll)
self.resize(600,550)
self.show()
app = QApplication([])
window = main()
app.exec()