I have dynamically created buttons(QtoolButton) in gridLayout in pyQT.
How can I get the name of the button clicked in the layout?
I can’t know the name before hand.
Is there is any trigger to accomplish the task?
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can call
self.sender()in a function connected to your button event to get the object that triggered the event. From there you can call the object’sobjectName()method to get the name.Here’s a quick example – the widget has 10 buttons and clicking on a button will update the label’s text to show the button name.