qfedu-qt-level/homework-day1/widget4.cpp

28 lines
674 B
C++
Raw Permalink Normal View History

2023-08-08 17:47:59 +08:00
#include "widget4.h"
Widget4::Widget4(QWidget *parent) : QWidget(parent)
{
setWindowTitle("题目4");
setFixedSize(800,600);
btn = new QPushButton("按钮",this);
btn->setFixedSize(200,100);
btn->move(10,10);
edit1 = new QLineEdit(this);
edit1->move(10,120);
edit2 = new QLineEdit(this);
edit2->move(10,160);
label = new QLabel("占位",this);
label->move(300,140);
connect(btn,&QPushButton::clicked,[&]()->void{
QString str1 = edit1->text();
QString str2 = edit2->text();
int res_num = str1.toInt()+str2.toInt();
label->setNum(res_num);
});
}