PyQt5 Python Scroll area can't scroll it's content

Question:

I can’t make scroll area scrolling.
Added into it QLabel and grid with 100 lines.
You can see code and screenshot bellow.
Does someone know how to add grid into scrolling area?

import sys
from PyQt5 import QtWidgets
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *


class Window(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setGeometry(100, 100, 960, 820)
        self.setMinimumWidth(960)
        self.setMinimumHeight(820)
        self.user_interface()

    def user_interface(self):
        self.setFont(QFont('Times', 11))
        # 100 lines grid
        grid = QGridLayout()
        for i in range(0, 100):
            for j in range(0, 1):
                grid.addWidget(QLabel("Hello There"), i, j)
                grid.addWidget(QLabel("General Kenobi"), i, j + 1)
        # scroll layout with QLabel and 100 lines grid
        scroll_layout = QVBoxLayout()
        scroll_layout.addWidget(QLabel("Scroll me down baby"))
        scroll_layout.addLayout(grid)
        scroll_layout.addStretch()
        # Creation of scroll area and set scroll layout as its layout
        scroll_area = QScrollArea()
        scroll_area.setLayout(scroll_layout)
        scroll_area.setWidgetResizable(False)
        # main layout
        main_layout = QtWidgets.QVBoxLayout()
        main_layout.addWidget(QLabel("I stay on my place"))
        main_layout.addWidget(scroll_area)
        # application GUI setup
        central_widget = QtWidgets.QWidget(self)
        self.setCentralWidget(central_widget)
        central_widget.setLayout(main_layout)
        self.show()


def main():
    app = QApplication(sys.argv)
    window = Window()
    sys.exit(app.exec())


if __name__ == '__main__':
    main()

Here is screenshot:
enter image description here

Thanks guys!

Asked By: Jan Chris Bilek

||

Answers:

Found solution for my question ->

https://www.pythonguis.com/tutorials/qscrollarea/

Answered By: Jan Chris Bilek
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.