#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
QString str_array1[3] = {"Game","Office","Develop"}; //check박스의 문자열로 사용
QString str_array2[3] = {"P&rogramming","Q&t","O&S"}; //&은 &앞에 나온문자가 단축키가됨
int xpos=30;
int ypos=30;
chk_group[0] = new QButtonGroup(this); //group1생성
chk_group[1] = new QButtonGroup(this); //group2생성
for(int i=0;i<3;i++)
{
exclusive[i]= new QCheckBox(str_array1[i],this); //str_array[i]문자열을 사용하여 체크박스 생성
exclusive[i]->setGeometry(xpos,ypos,100,50); //x축,y축,높이,넓이
chk_group[0]->addButton(exclusive[i]); //chk_group[1]애 exclusive[i]를 추가
non_exclusive[i] = new QCheckBox(str_array2[i],this);
non_exclusive[i]->setGeometry(xpos+130,ypos,100,50); //x축,y축,높이,넓이
chk_group[1]->addButton(non_exclusive[i]); //chk_group[1]에 non_exclusive[i]를 추가
connect(exclusive[i],SIGNAL(clicked()),this,SLOT(chk_Changed()));
ypos +=40;
}
chk_group[0] ->setExclusive(true); //중복선택 불가능
chk_group[1]->setExclusive(false); //중복선택 가능
ui->setupUi(this);
}
void Widget::chk_Changed()
{
qDebug()<<"Click Changed!!";
}
Widget::~Widget()
{
}
CheckBoxAndGroup.zip
0.00MB