MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString str1[3] = {"Game", "Office", "Develop"};
QString str2[3] = {"P&rogramming", "Q&t", "O&S"};
int xpos = 30;
int ypos = 30;
chk_group[0] = new QButtonGroup(this);
chk_group[1] = new QButtonGroup(this);
for(int i = 0 ; i < 3 ; i++)
{
exclusive[i] = new QCheckBox(str1[i], this);
exclusive[i]->setGeometry(xpos, ypos, 100, 30);
chk_group[0]->addButton(exclusive[i]);
non_exclusive[i] = new QCheckBox(str2[i], this);
non_exclusive[i]->setGeometry(xpos + 120, ypos, 100, 30);
chk_group[1]->addButton(non_exclusive[i]);
ypos += 40;
}
chk_group[0]->setExclusive(false);
chk_group[1]->setExclusive(true);
}
第一组 复选 第二组 可以单选
为什么把这个 non_exclusive[i]->setGeometry(xpos + 120, ypos, 100, 30); 改个值
non_exclusive[i]->setGeometry(xpos + 120, ypos, 100, 100); 就能用了呢