1. 程式人生 > 其它 >Qt之QRadioButton多選一

Qt之QRadioButton多選一

技術標籤:pythonlinux正則表示式htmlmysql

QRadioButton多選一,QCheckBox多選多

    QString str1[3] = {"NetBook", "Handset", "Tablet"};

    QRadioButton *radio1[3];
    QRadioButton *radio2[3];

    int ypos = 30;
    for(int i = 0; i < 3; ++i){
        radio1[i] = new QRadioButton(str1[i], this);
        radio1[i]->setGeometry(10, ypos, 150, 30);

        ypos += 40;
    }

    QString str2[3] = {"In-Vehicle", "SmartTV", "Media Phone"};
    ypos = 30;
    for(int i = 0; i < 3; ++i){
        radio2[i] = new QRadioButton(str2[i], this);
        if(i == 2)
            radio2[i]->setChecked(true);  //預設選中

        radio2[i]->setGeometry(180, ypos, 150, 30);

        ypos += 40;
    }

    //使用QButtonGroup分組實現分離
    QButtonGroup *group1 = new QButtonGroup(this);
    QButtonGroup *group2 = new QButtonGroup(this);

    group1->addButton(radio1[0]);
    group1->addButton(radio1[1]);
    group1->addButton(radio1[2]);

    group2->addButton(radio2[0]);
    group2->addButton(radio2[1]);
    group2->addButton(radio2[2]);

5dd1b2f18b1e1333709c2b8520ae8a608e7.jpg