A
A
alex_noob2282021-07-14 08:34:30
PyQt
alex_noob228, 2021-07-14 08:34:30

PyQt5 QButtonGroup() how to pass pressed button name to function?

I am writing invincible tic-tac-toe, here is a piece of code with a problem:

self.btn_grp = QButtonGroup()
        self.btn_grp.setExclusive(True)
        self.btn_grp.addButton(self.pushButton_6, id = 6)
        self.btn_grp.addButton(self.pushButton_7, id = 7)
        self.btn_grp.addButton(self.pushButton_2, id = 2)
        self.btn_grp.addButton(self.pushButton_1, id = 1)
        self.btn_grp.addButton(self.pushButton_5, id = 5)
        self.btn_grp.addButton(self.pushButton_9, id = 9)
        self.btn_grp.addButton(self.pushButton_8, id = 8)
        self.btn_grp.addButton(self.pushButton_3, id = 3)
        self.btn_grp.addButton(self.pushButton_4, id = 4)
        self.btn_grp.checkedId()
        self.btn_grp.buttonClicked.connect(self.pressed())

I did not understand anything from the documentation, except for it I did not find anything useful.
How to pass the name of the pressed button through conect to a function or at least id?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ronald McDonald, 2021-07-14
@Zoominger

Qt has a special sender() function that returns the object that was clicked.
Call it and get the button name through it.

B
bbkmzzzz, 2021-07-14
@bbkmzzzz

buttonClicked

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question