QGroupBox QToolBox QComboBox 实现组合框 基本控件(五)

一、效果图
在这里插入图片描述
QGroupBox
为构建分组框提供了支持。分组框通常带有一个边框和一个标题栏,作为容器部件来使用,在其中可以布置各种窗口部件

QToolBox
提供了一种列状层叠窗口

QComboBox
提供一个一种下拉列表框组件

二、代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "boxswidget.h"
#include "ui_boxswidget.h"
#include <QGroupBox>
#include <QCheckBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QToolBox>
#include <QLabel>
#include <QComboBox>
#include <QTimer>
BoxsWidget::BoxsWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BoxsWidget)
{
    ui->setupUi(this);

    QGroupBox *groupBox = new QGroupBox("Type0");
    QCheckBox *check0 = new QCheckBox("check0-0");
    QCheckBox *check1 = new QCheckBox("check1-0");
    QCheckBox *check2 = new QCheckBox("check2-0");
    QVBoxLayout *vlayout = new QVBoxLayout(groupBox);
    vlayout->addWidget(check0);
    vlayout->addWidget(check1);
    vlayout->addWidget(check2);
    vlayout->addStretch();

    QGroupBox *groupBox1 = new QGroupBox("Type1");
    QCheckBox *check01 = new QCheckBox("check0-1");
    QCheckBox *check11 = new QCheckBox("check1-1");
    QCheckBox *check21 = new QCheckBox("check2-1");
    QVBoxLayout *vlayout1 = new QVBoxLayout(groupBox1);
    vlayout1->addWidget(check01);
    vlayout1->addWidget(check11);
    vlayout1->addWidget(check21);
    vlayout1->addStretch();

    QGroupBox *groupBox2 = new QGroupBox("Type2");
    QCheckBox *check02 = new QCheckBox("check0-2");
    QCheckBox *check12 = new QCheckBox("check1-2");
    QCheckBox *check22 = new QCheckBox("check2-2");
    QVBoxLayout *vlayout2 = new QVBoxLayout(groupBox2);
    vlayout2->addWidget(check02);
    vlayout2->addWidget(check12);
    vlayout2->addWidget(check22);
    vlayout2->addStretch();

    QToolBox *toolbox = new QToolBox;
    toolbox->addItem(groupBox,"Type-0");
    toolbox->addItem(groupBox1,"Type-1");
    toolbox->addItem(groupBox2,"Type-2");
    toolbox->resize(this->size());
    toolbox->show();

    QWidget *w = new QWidget;
    QVBoxLayout *vlayout0 = new QVBoxLayout;
    QComboBox *combox = new QComboBox;
    combox->addItem("item0");
    combox->addItem("item1");
    combox->addItem("item2");
    combox->addItem("item3");
    combox->addItem("item4");

    vlayout0->addWidget(combox);
    vlayout0->addStretch();
    w->setLayout(vlayout0);

    ui->horizontalLayout_2->addWidget(toolbox);
    ui->horizontalLayout_2->addWidget(w);

    show();
}

BoxsWidget::~BoxsWidget()
{
    delete ui;
}