In PyQt5 I generate as many QPushButtons as there are items in a list, like:
self.modelsButton = [QtWidgets.QPushButton(self.resultsWidget) for x in modelsDefined]
And then I make them execute a function when clicked:
[self.ui.modelsButton[i].clicked.connect(self.populateDetailsTab) for i in range(len(self.modelsDefined))]
The function populateDetailsTab
will attempt to pull the text details of the button clicked, but I can't decipher which button was clicked. I tried to pull the text of the button directly via the following:
[self.ui.modelsButton[i].clicked.connect(self.populateDetailsTab(self.ui.modelsButton[i].text().split[0])) for i in range(len(self.modelsDefined))]
But this throws an error: TypeError: 'builtin_function_or_method' object is not subscriptable
.
Can someone please help me identify which button was clicked? There are a decent number of buttons generated in my script.