I have QMainWindow that is limited by the maximum height of 900px. And I want QScrollArea to use all available space in the height axis of this window if the area has ability to grow in height.
When I run app QMainWindow chooses some value for height that is not maximum but if I stretch QMainWindow manually to maximum height QScrollArea with a lot of widgets in it looks also pretty. So why doesn't it use all availabe space from the start of the program?
Here the snippet of code that demonstrates this situation:
class UI(QMainWindow):
def __init__(self):
super().__init__()
self.setFixedWidth(500)
self.setMaximumHeight(900)
mainWidget = QWidget()
mainlLayout = QVBoxLayout()
scrollArea = QScrollArea()
mainWidget.setLayout(mainlLayout)
scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
scrollArea.setWidgetResizable(True)
scrollArea.setWidget(mainWidget)
self.setCentralWidget(scrollArea)
for i in range(30):
buts = QHBoxLayout()
for j in range(3):
buts.addWidget(QPushButton('Yet Another Button'))
mainlLayout.addLayout(buts)
def main():
app = QApplication(sys.argv)
ui = UI()
ui.show()
sys.exit(app.exec_())