Skip to content

Instantly share code, notes, and snippets.

@fridezlucas
Last active November 30, 2019 15:07
Show Gist options
  • Save fridezlucas/abe29ef87e2f996f6f1c3ca56b043a34 to your computer and use it in GitHub Desktop.
Save fridezlucas/abe29ef87e2f996f6f1c3ca56b043a34 to your computer and use it in GitHub Desktop.
[Qt RadioButton With Group] Radio Buttons with specified groups #qt
#include "widget.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QButtonGroup>
#include <QRadioButton>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QHBoxLayout *lytMain = new QHBoxLayout(this);
QButtonGroup* btnGrp1 = new QButtonGroup(this);
QButtonGroup* btnGrp2 = new QButtonGroup(this);
QRadioButton* chk1_1 = new QRadioButton("1.1", this);
QRadioButton* chk1_2 = new QRadioButton("1.2", this);
QRadioButton* chk2_1 = new QRadioButton("2.1",this);
QRadioButton* chk2_2 = new QRadioButton("2.2",this);
QVBoxLayout* lytV1 = new QVBoxLayout(this);
QVBoxLayout* lytV2 = new QVBoxLayout(this);
btnGrp1->addButton(chk1_1);
btnGrp1->addButton(chk1_2);
btnGrp2->addButton(chk2_1);
btnGrp2->addButton(chk2_2);
lytV1->addWidget(chk1_1);
lytV1->addWidget(chk1_2);
lytV2->addWidget(chk2_1);
lytV2->addWidget(chk2_2);
lytMain->addLayout(lytV1);
lytMain->addLayout(lytV2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment