当前位置:网站首页>Qt学习08 启航!第一个应用实例
Qt学习08 启航!第一个应用实例
2022-06-29 10:30:00 【一个小黑酱】
Qt学习08 启航!第一个应用实例
计算器程序界面分析

QLineEdit组件
- QLineEdit用于接受用户输入
- QLineEdit能够获取用户输入的字符串
- QLineEdit是功能性组件,需要父组件作为容器
- QLineEdit能够在父组件中进行定位
QWidget w; // 生成QWidget对象,顶级组件
QLineEdit le(&w); // 生成QLineEdit对象,其父组件为QWidget
le.setAlignment(Qt::AlignRight); // 设置显示字符串向右边对其
le.move(10, 10); // 移动到坐标(10, 10)
le.resize(240, 30); // 设置大小width=240, height=30
设计与实现
界面设计
定义组件间的间隔
Space = 10px
定义按钮组件的大小
Width = 40px,Height = 40px
定义文本框组件的大小
Width = 5 * 40px + 4 * 10px,Height = 30px

- 存在的问题
- 计算器程序不需要最大化和最小化按钮
- 计算器程序的窗口应该是固定大小
- 文本框不能直接输入字符
#include <QtGui/QApplication>
#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget* w = new QWidget(NULL, Qt::WindowCloseButtonHint);
QLineEdit* le = new QLineEdit(w);
QPushButton* button[20] = {
0};
const char* btnText[20] =
{
"7", "8", "9", "+", "(",
"4", "5", "6", "-", ")",
"1", "2", "3", "*", "<-",
"0", ".", "=", "/", "C",
};
int ret = 0;
le->move(10, 10);
le->resize(240, 30);
le->setReadOnly(true);
for(int i=0; i<4; i++)
{
for(int j=0; j<5; j++)
{
button[i*5 + j] = new QPushButton(w);
button[i*5 + j]->resize(40, 40);
button[i*5 + j]->move(10 + (10 + 40)*j, 50 + (10 + 40)*i);
button[i*5 + j]->setText(btnText[i*5 + j]);
}
}
w->show();
w->setFixedSize(w->width(), w->height());
ret = a.exec();
delete w;
return ret;
}
小结
- GUI应用程序开发前应前必须先进行界面设计
- GUI应用程序界面需要考虑各个细节
- 界面决定最终用户的体验
- 界面细节是GUI应用程序品质的重要体现
- Qt库有能力实现各种GUI应用程序需求
必须先进行界面设计** - GUI应用程序界面需要考虑各个细节
- 界面决定最终用户的体验
- 界面细节是GUI应用程序品质的重要体现
- Qt库有能力实现各种GUI应用程序需求
- Qt帮助文档的使用对于开发是非常重要的
边栏推荐
- 多线程高并发服务器:3个问题
- LVGL库入门教程 - 动画
- MySQL开启慢查询
- Take another picture of cloud redis' improvement path
- (JS) handwritten bind function
- Encore une fois, le chemin de l'amélioration de redis Cloud
- Shell 引号和转义从来很少被人注意,但平时写脚本又经常用
- (JS) array de duplication
- Several types of MySQL index invalidation and their solutions
- 【HBZ分享】Mysql的InnoDB原理
猜你喜欢

安全 创新 实践|海泰方圆受邀参加“数字时代的网信创新与价值共创”技术交流研讨会

Xuetong denies that the theft of QQ number is related to it: it has been reported; IPhone 14 is ready for mass production: four models are launched simultaneously; Simple and elegant software has long

Hit the industry directly! The first model selection tool in the industry was launched by the flying propeller

BS-GX-018 基于SSM实现在校学生考试系统

【每日3题(1)】判断国际象棋棋盘中一个格子的颜色

misc3~7

中国计算语言学大会、全国知识图谱与语义计算大会赛题火热进行中

ruoyi框架中添加sharding sphere5.0.0分表(通过spi添加自定义分表策略)

Multithreaded high concurrency server: three problems

微博评论架构设计
随机推荐
Week 12 experiment -- implementation of VGA protocol based on FPGA
MySQL开启慢查询
crypto 1~5
(JS) catch errors (exceptions)
[3 questions per day (2)] minimum operand for generating alternate binary strings
如何识别出轮廓准确的长和宽
[daily 3 questions (1)] judge the color of a grid on the chess board
Nuc980 open source project 16- start from SPI flash (w25q128)
Multithreaded high concurrency server: three problems
Several types of MySQL index invalidation and their solutions
Mysql获取表信息
Doodle cloud development demo login
Interview questions of Tencent automation software test of CSDN salary increase secret script (including answers)
LeetCode 535 TinyURL的加密与解密[map] HERODING的LeetCode之路
那些大佬经常在bash 命令行终端不经意间666飞起的必备操作
[various * * question series] what are OLTP and OLAP?
直击产业落地!飞桨重磅推出业界首个模型选型工具
(JS) pure function in array
How to obtain method parameter values through WinDbg
math_ Mathematical expression & deformation of equation equation & accumulation of combined operation skills / means