C++

C++ Qt

C++ Qt로 간단한 GUI만들기

사진과 같은 GUI를 구현 해보자!.

프로젝트명은 QtWidgetsApplication1 로 생성하였다.

UI 구성


h.파일코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#pragma once

#include <QtWidgets/QDialog>
#include "ui_QtWidgetsApplication1.h"

class QtWidgetsApplication1 : public QDialog
{
Q_OBJECT

public:
QtWidgetsApplication1(QWidget *parent = Q_NULLPTR);

private:
Ui::QtWidgetsApplication1Class ui;

public slots:
void btn_run_clicked();
};

cpp.파일코드

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
#include "QtWidgetsApplication1.h"

QtWidgetsApplication1::QtWidgetsApplication1(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
connect(ui.btn_run, SIGNAL(clicked()), this, SLOT(btn_run_clicked()));
connect(ui.checkBox_1, SIGNAL(clicked()), this, SLOT(checkBox1_clicked()));
connect(ui.checkBox_2, SIGNAL(clicked()), this, SLOT(checkBox2_clicked()));
connect(ui.checkBox_3, SIGNAL(clicked()), this, SLOT(checkBox3_clicked()));
connect(ui.checkBox_4, SIGNAL(clicked()), this, SLOT(checkBox3_clicked()));

ui.comboBox->addItem("Male");
ui.comboBox->addItem("FeMale");

}

void QtWidgetsApplication1::btn_run_clicked()
{
ui.label_6->setText("Age:" + ui.spinBox->cleanText());

ui.label_5->setText("Gender:" + ui.comboBox->currentText());

QString chk1 = "", chk2 = "", chk3 = "", chk4="";
if (ui.checkBox_1->isChecked())
chk1 = "Hobby :Watching Movie";
if (ui.checkBox_2->isChecked())
chk2 = "Hobby :Sports";
if (ui.checkBox_3->isChecked())
chk3 = "Hobby :Drawing";
if (ui.checkBox_4->isChecked())
chk3 = "Hobby :Pet";
ui.label_4->setText(QString("\n%1 \n%2 \n%3 \n%4").arg(chk1, chk2, chk3, chk4));
};

실행결과

Share