I have a program that creates a number of qlineedits and buttons depending on the users input:
On the image above 4 lines have been added with a button after the grayed out "Next" button was clicked. Now I want to get the input from the user into a function when the corresponding button is clicked (Click "Create Shot 1! --> goto a function with "exShot1" passed as an argument).
The thing is I have no idea how to get the names of each qline and button when they are created in a loop. I guess I could create unique variables in the loop but that doesn't feel right. I have tried using setObjectName
but I can't figure out how I can use that to call the text. I also made an unsuccessful attempt with Lamdba (which I have a feeling might be the right way to go somehow) I believe it's a combination of having to fetch the name and tracking when the user input is changed.
I have experimented with textChanged
and I got it to work on the last entry of the loop but not for the other qlines and buttons)
Relevant code:
while i <= int(seqNum):
#create each widget
self.createShotBtn = QtGui.QPushButton("Create Shot %s!" %str(self.shotNumberLst[i-1]))
self.labelName = QtGui.QLabel(self)
self.labelName.setText("Enter Name Of Shot %s!" %str(self.shotNumberLst[i-1]))
self.shotName = QtGui.QLineEdit(self)
self.shotName.setObjectName("shot"+str(i))
#add widget to layout
self.grid.addWidget(self.labelName, 11+shotjump,0)
self.grid.addWidget(self.shotName,11+shotjump,1)
self.grid.addWidget(self.createShotBtn, 11+shotjump,2)
#Press button that makes magic happen
self.createShotBtn.clicked.connect(???)
i += 1
edit: It would also be fine if the user entered input on all the lines and just pressed one button that passed all those inputs as a list or dict (there will be more lines added per "shot")