Qt5-control-QRadioButton-single choice button-used to select one from multiple options-single choice artifact, qt5 -- qradiobutton-
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include <QRadioButton>#include <QButtonGroup>class MainWindow : public QMainWindow{ Q_OBJECTpublic: MainWindow(QWidget *parent = 0); ~MainWindow(); QRadioButton* radio0[10]; QRadioButton* radio1[10]; QButtonGroup* group[10];};#endif // MAINWINDOW_H
# Include "mainwindow. h "MainWindow: MainWindow (QWidget * parent): QMainWindow (parent) {this-> resize (400,300); this-> centralWidget (); QString str0 [] = {"laptop", "phone", "Printer"}; QString str1 [] = {"radish", "cabbage", "green pepper "}; group [0] = new QButtonGroup (this); group [1] = new QButtonGroup (this); int xpos = 10, ypos = 30; for (int I = 0; I <3; I ++) {radio0 [I] = new QRadioButton (str0 [I], this); group [0]-> addButton (radio0 [I]); Radio0 [I]-> setGeometry (xpos, ypos, 100,30); radio1 [I] = new QRadioButton (str1 [I], this ); group [1]-> addButton (radio1 [I]); radio1 [I]-> setGeometry (xpos + 110, ypos,); ypos + = 50 ;}} MainWindow: :~ MainWindow (){}
#include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; w.show(); return a.exec();}