|
| 1 | +#! /usr/bin/python3 -B |
| 2 | + |
| 3 | +import itertools |
| 4 | +import PyQt5.QtCore as QtCore |
| 5 | +import PyQt5.QtWidgets as QtWidgets |
| 6 | + |
| 7 | +from ScrollableContainers.Qt5 import ScrollableAreaQt5 |
| 8 | + |
| 9 | +############################################################################### |
| 10 | + |
| 11 | +def grid_of_widgets(): |
| 12 | + app = QtWidgets.QApplication(['`ScrollableAreaQt5` demo']) |
| 13 | + window = QtWidgets.QMainWindow() |
| 14 | + |
| 15 | + # Create a scrollable area. |
| 16 | + scrollable_area = ScrollableAreaQt5() |
| 17 | + |
| 18 | + # Add widgets to the `area` attribute of the scrollable area, not to the |
| 19 | + # scrollable area itself. |
| 20 | + dim = 10 |
| 21 | + grid_layout = QtWidgets.QGridLayout(scrollable_area.area) |
| 22 | + for (i, j) in itertools.product(range(dim), repeat=2): |
| 23 | + grid_layout.addWidget(QtWidgets.QLabel(text=f'Label\n({i}, {j})'), i, j) |
| 24 | + |
| 25 | + window.setCentralWidget(scrollable_area) |
| 26 | + window.show() |
| 27 | + app.exec_() |
| 28 | + |
| 29 | +############################################################################### |
| 30 | + |
| 31 | +def single_widget(): |
| 32 | + app = QtWidgets.QApplication(['`ScrollableAreaQt5` demo']) |
| 33 | + window = QtWidgets.QMainWindow(size=QtCore.QSize(600, 200)) |
| 34 | + |
| 35 | + scrollable_area = ScrollableAreaQt5() |
| 36 | + |
| 37 | + vbox = QtWidgets.QVBoxLayout(scrollable_area.area) |
| 38 | + vbox.addWidget(QtWidgets.QLabel(text='big window, small label')) |
| 39 | + |
| 40 | + window.setCentralWidget(scrollable_area) |
| 41 | + window.show() |
| 42 | + app.exec_() |
| 43 | + |
| 44 | +############################################################################### |
| 45 | + |
| 46 | +if __name__ == '__main__': |
| 47 | + grid_of_widgets() |
| 48 | + single_widget() |
0 commit comments