Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Qt/C++] QButtonGroup which allow to set the checked radio button by its id
#ifndef QBUTTONGROUPEXT
#define QBUTTONGROUPEXT
#include <QButtonGroup>
#include <QAbstractButton>
/**
* @brief QButtonGroup which allow to set the checked radio button by its id
*/
class QButtonGroupExt : public QButtonGroup
{
Q_OBJECT
public:
QButtonGroupExt(QWidget* _parent = 0) : QButtonGroup(_parent) {}
void setCheckedId(int _id)
{
foreach (QAbstractButton* button, buttons())
{
if (id(button) == _id)
{
button->setChecked(true);
break;
}
}
}
};
#endif // QBUTTONGROUPEXT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment