Qt小案例《加法器》
要使用到的头文件
- QApplication
- QWidget
- QLabel
- QLineEdit
- QPushButton
- QDoubleValidator
- QHBoxLayout
案例的要求
- 实现一个加法器(简单的数字计算)
- 水平布局,可任意缩放
- x+y=z
- x和y只接受数字;z只能展示x+y的结果,不能编辑
- 在x和y的内容是正确之前等号的按钮是禁用的
效果展示
- x和y没有数字的时候,等号按钮是灰的(禁用的)
- x和y都有数字的时候,等号的按钮是亮的(可使用的)
- 按下“=”按钮后计算出结果,结果在第三个空显示
源代码
#include <QApplication>
#include "mywidget.h"
int main(int argc,char** args)
{
QApplication app(argc,args);
MyWidget w;
w.show();
return app.exec();
}
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>