Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PyQt5 import QtWidgets, QtCore
- class ScrollArea(QtWidgets.QScrollArea):
- def __init__(self, parent = None):
- super().__init__(parent)
- self._buttons = []
- widget = QtWidgets.QWidget()
- layout = QtWidgets.QVBoxLayout()
- widget.setLayout(layout)
- self.setWidget(widget)
- self.setWidgetResizable(True)
- def addButton(self):
- index = len(self._buttons)
- text = "button {}".format(index)
- button = QtWidgets.QPushButton(text)
- self.widget().layout().addWidget(button)
- self._buttons.append(button)
- button.clicked.connect(self.addButton)
- return button
- if __name__ == "__main__":
- app = QtWidgets.QApplication(sys.argv)
- widget = ScrollArea()
- QtCore.QTimer.singleShot(0, lambda: widget.addButton())
- QtCore.QTimer.singleShot(0, lambda: widget.addButton())
- widget.show()
- exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement