当前位置:网站首页>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帮助文档的使用对于开发是非常重要的
边栏推荐
- 在编写shell脚本时如何正确姿势地管理临时文件
- Add notification announcements to send notifications to online users
- (JS) handwriting depth comparison
- (JS) iterator mode
- Bs-gx-018 student examination system based on SSM
- [digital signal modulation] realize signal modulation and demodulation based on am+fm+dsb+ssb, including Matlab source code
- [3 questions per day (2)] minimum operand for generating alternate binary strings
- 【数字信号调制】基于 AM+FM+DSB+SSB实现信号调制解调含Matlab源码
- Necessary for cloud native development: the first common codeless development platform IVX editor
- Multithreaded high concurrency server: three problems
猜你喜欢

云原生开发必备:首个通用无代码开发平台 iVX 编辑器

期未课程设计:基于SSM的产品销售管理系统

直击产业落地!飞桨重磅推出业界首个模型选型工具

多线程高并发服务器:3个问题

又拍雲 Redis 的改進之路

Online sql to htmltable tool

斐波那锲数列与冒泡排序法在C语言中的用法

Specific method and example program of Siemens s7-200smart control stepping motor

Multithreaded high concurrency server: three problems

巴比特 | 元宇宙每日必读:HTC 宣布推出首款元宇宙手机,售价约2700元人民币,都有哪些新玩法?...
随机推荐
(JS) pure function in array
MySQL query table field information
Modbus RTU protocol 485 learning 2-way infrared module
通过网上进行股票开户安全吗
Shell 中你不得不熟知的变量运用
How to properly manage temporary files when writing shell scripts
(JS) array methods: slice and slice
CTO专访:合见工软深化产品布局 加速国产EDA技术革新
LeetCode 535 TinyURL的加密与解密[map] HERODING的LeetCode之路
[3 questions per day (2)] minimum operand for generating alternate binary strings
ModbusTCP协议网络学习型单路红外模块(中壳版)
Map merges the same keys and values into a list
如何识别出轮廓准确的长和宽
添加通知公告,给在线用户发送通知
工具箱之 IKVM.NET 项目新进展
misc3~7
Mastering the clever use of some shell wildcards will make us write with half the effort
Google Earth Engine(GEE)——GEDI L2A Vector Canopy Top Height (Version 2) 全球生态系统数据集
Live broadcast by technical experts from China Kuwait Fangde: how to build a private cloud platform based on openstack and CEPH| Issue 27
Babbitt | yuancosmos daily must read: HTC announced the launch of the first yuancosmos mobile phone, which costs about 2700 yuan. What are the new ways to play