Ik weet niet juist wat je probeert te doen, maar hier is een volledig voorbeeld op basis van PySide2 (Qt 5) om op basis van die array een grid met QLineEdit elementen te maken en waar we de setText() functie gebruiken. Daarnaast wordt er een label bijgewerkt zodra één van de QLineEdit elementen wordt aangepast. Ben je daar iets mee?
from PySide2.QtWidgets import QApplication, QDialog, QGridLayout, QLabel, QLineEdit
import sys
cnames = ["c00", "c01","c02", "c03", "c04", "c05",
"c10", "c11", "c12", "c13", "c14", "c15",
"c20", "c21", "c22", "c23", "c24", "c25",
"c30", "c31", "c32", "c33", "c34", "c35",
"c40", "c41", "c42", "c43", "c44", "c45",
"c50", "c51", "c52", "c53", "c54", "c55",
"c60", "c61", "c62", "c63", "c64", "c65",
"c70", "c71", "c72", "c73", "c74", "c75"]
class Dialog(QDialog):
def __init__(self, parent=None):
super(Dialog, self).__init__(parent)
self.setWindowTitle("Application name")
# Create grid layout
self.grid = QGridLayout()
self.setLayout(self.grid)
# Add label to test signal/slot of line edits
self.label = QLabel()
self.label.setText("Change something...")
self.grid.addWidget(self.label, 0, 0)
# Create the different line edits based on cnames
# And add it to a grid layout
self.lineEdits = {}
for cname in cnames:
row = int(cname[1])
col = int(cname[2])
lineEdit = QLineEdit()
lineEdit.setText("Test " + cname)
lineEdit.textChanged.connect(self.updateLabel)
self.grid.addWidget(lineEdit, row + 1, col)
self.lineEdits[cname] = lineEdit
def updateLabel(self, text):
self.label.setText("Updated to: " + text)
if __name__ == '__main__':
app = QApplication(sys.argv)
dialog = Dialog()
dialog.show()
sys.exit(app.exec_())