widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QRadioButton> //单选按钮
#include <QGroupBox> //分组框
#include <QHBoxLayout> //水平布局
#include <QVBoxLayout> //垂直布局
#include <QPushButton> //按钮
#include <QLabel> //标签
#include <QLineEdit> //行编辑器
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
private:
QRadioButton *rb[4]; //4个单选按钮
QGroupBox *grpbox; //分组框
QPushButton *pb; //按钮
QLabel *lb; //标签
QLineEdit *le; //行编辑器
};
#endif // WIDGET_H
widget.cpp
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
setFixedSize(430,320); //设置主窗口大小
grpbox = new QGroupBox("贵州的省会是?",this); //创建分组框
QStringList list = {"成都","贵阳","长沙","深圳"}; //保存单选按钮名字
QVBoxLayout