大家好,我是 DongGu ,是一名软件工程专业大二的学生,写博客一方面是为了记录自己的学习过程,把自己犯的错误进行分享。但由于水平有限,博客中难免会有一些错误出现,有纰漏之处恳请各位大佬不吝赐教!有任何问题可以评论或者QQ联系(1521839703)
个人博客网站也搭好啦: dongguxy.top
效果如图:
widget.cpp
#include "widget.h"
#include <QLineEdit>
#include <QPushButton>
#include <QDebug>
#include <QString>
#include <QMessageBox>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QLineEdit * Line1 = new QLineEdit();
QLineEdit * Line2 = new QLineEdit();
// 设置窗口大小
setFixedSize(500,500);
setWindowTitle("DongGu's bim");
// 设置文本框大小,并依靠在父类窗口下
Line1->setFixedSize(300,20);
Line2->setFixedSize(300,20);
Line1->setParent(this);
Line2->setParent(this);
// 移动固定位置
Line1->move(100,100);
Line2->move(100,200);
// 设置默认提示
Line1->setPlaceholderText(QString("输入体重(/kg)"));
Line2->setPlaceholderText(QString("输入身高(/m)"));
QPushButton * bt1 = new QPushButton(QString("显示bim值"));
bt1->setParent(this);
bt1->move(200,300);
// 点下按钮进行计算
connect(bt1,&QPushButton::clicked,this,[=](){
float kg = Line1->text().toFloat();
float cm = Line2->text().toFloat();
float bim = kg/ (cm * cm);
QMessageBox * mes = new QMessageBox();
QString str = QString("bim 值是 %1").arg(bim);
qDebug() << str;
int k = mes->information(this, "bim", str, "退出","继续");
if (k == 0){
qDebug() << k << "退出";
this->close();
}
});
}
Widget::~Widget()
{
}