Skip to content

Instantly share code, notes, and snippets.

@mistic100
Created January 10, 2016 12:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mistic100/dcbffbd9e9c15271dd14 to your computer and use it in GitHub Desktop.
Save mistic100/dcbffbd9e9c15271dd14 to your computer and use it in GitHub Desktop.
[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