I wanted to Add labels using the loop via after pressing the Button so I can check if the pyqt5 scroll area is working. But I'm unable to do so. I know somewhere I'm doing wrong.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QScrollArea, QVBoxLayout, QGroupBox, QLabel,
QPushButton, QFormLayout
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(700, 394)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(320, 30, 61, 31))
font = QtGui.QFont()
font.setFamily("Roboto Medium")
font.setPointSize(14)
self.label.setFont(font)
self.label.setObjectName("label")
self.update = QtWidgets.QPushButton(self.centralwidget)
self.update.setGeometry(QtCore.QRect(300, 300, 121, 41))
self.update.setObjectName("update")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.update.clicked.connect(self.update_function)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label.setText(_translate("MainWindow", "Scroll"))
self.update.setText(_translate("MainWindow", "Update"))
def update_function(self):
n = 20
labelLis = []
text = 'Inside the scroll area'
for i in range(n):
labelLis.append(QLabel(text))
self.formLayout.addRow(labelLis[i])
self.groupBox.setLayout(formLayout)
area = QScrollArea()
area.setWidget(self.formLayout)
area.setGeometry(140, 70, 431, 221)
area.setWidgetResizable(True)
layout = QVBoxLayout(self)
layout.addWidget(area)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Im getting this exit code:
Process finished with exit code -1073740791 (0xC0000409)
User contributions licensed under CC BY-SA 3.0