Return a QPushButton from a QButtonGroup by id?
Solved
General and Desktop
-
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 *? -
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); }