Return a QPushButton from a QButtonGroup by id?
-
wrote on 10 Aug 2020, 02:45 last edited by
I have a group of
QPushButton
and I added them to aQButtonGroup
with id. I want to programatically setcheck one of the button. In order to do that, I need to get that button first, but how do I get it by id? -
wrote on 10 Aug 2020, 02:48 last edited by Bonnie 8 Oct 2020, 02:50
How about reading the doc first :)
QAbstractButton *QButtonGroup::button(int id) const
Or do you just not know how to cast a QAbstractButton * to QPushButton *? -
How about reading the doc first :)
QAbstractButton *QButtonGroup::button(int id) const
Or do you just not know how to cast a QAbstractButton * to QPushButton *? -
wrote on 10 Aug 2020, 08:11 last edited by
For some reason I couldn't check the button. I have four buttons in the group with value -2, 0, 1, 2. The target button was returned but
setCheck(true)
didn't do anything. I checked thecheckedId
of the buttonGroup, it always returns -1 when this event was triggered.qDebug() << "checked id is: " << ui->buttonGroup->checkedId(); QAbstractButton * targetBtn= ui->buttonGroup->button(2); if (targetBtn!= nullptr) { blockSignals(true); targetBtn->setChecked(true); blockSignals(false); }
-
For some reason I couldn't check the button. I have four buttons in the group with value -2, 0, 1, 2. The target button was returned but
setCheck(true)
didn't do anything. I checked thecheckedId
of the buttonGroup, it always returns -1 when this event was triggered.qDebug() << "checked id is: " << ui->buttonGroup->checkedId(); QAbstractButton * targetBtn= ui->buttonGroup->button(2); if (targetBtn!= nullptr) { blockSignals(true); targetBtn->setChecked(true); blockSignals(false); }
1/7