This is an example of using a QButtonGroup .
Group your radio buttons with QButtonGroup , if you havenβt already. For each button, use QButtonGroup::addButton(button, id) to assign consecutive identifiers to your buttons, starting from zero.
Then, to get the button index, use QButtonGroup::checkedId() .
When you use the Qt constructor to design your form, you can group the buttons by selecting them and choosing Assign to Button Group> New Button Group in the context menu. But I think that you cannot manually assign identifiers to buttons in a group. Instead, use QButtonGroup::setId(button, id) after setupUI to change the automatically assigned identifiers. (They are a bit confusing, considering minus s -2, and I donβt know how the designer chooses the order exactly, so I would not recommend depending on this order.)
source share