Alright, so I'm pretty deep into an app I'm making using PyQt5 and I have a section (QScrollArea) where I essentially have multiple lines of "accounts" which are QWidgets. The user can add an account and delete an account, but I would like to give them the ability to edit an account. On the same row as the account is a QPushButton, which is basically the edit button. If I have 3 accounts, then I can see 3 buttons. However, when I click the button for any account, all of the buttons refer to the exact same button object. I am storing the objects in a list and using findChildren() to get the objects. Both of these will give me three different button objects, but using clicked.connect() with the buttons reference only the latest, or bottom-most, button.
I am calling the clicked.connect() function after the part of my code that adds the account. I have also tried moving this to right below where I instantiate the button, but it didn't work.
Here is what I have:
btns = self.accountsWidget.findChildren(QPushButton)
for btn in btns:
btn.clicked.connect(lambda: self.editAccount(btn))
The method I call to try to edit the account is here:
def editAccount(self, btn):
print(btn)
self.editAccountWindow = EditAccountsWindow()
self.editAccountWindow.show()
The result of what's printed is always the last QPushButton object, and I'm only printing to see if I referenced the button I wanted to. That method just opens up a window, but what's shown on the window depends on calling the correct object. I want to use the object to reference which account I want to edit.
I have looked on many SO threads and could not find anything similar to this. I think I'm missing something, so please help a brother out :)