Created
January 10, 2016 12:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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