创建文本框控件

创建文本框控件也是和之前的一样,其实代码上都差不多的,就是创建控件然后设置位置。

QLineEdit* lineEdit = new QLineEdit(this );
lineEdit->setGeometry(200, 130, 200, 50);

文本框控件的主要功能就是输入,你可以在上面输入任何内容(无限制时)。

到现在的完整代码:

#include "MyFirstQt6.h"
#include <QtWidgets>

MyFirstQt6::MyFirstQt6(QWidget* parent)
: QMainWindow(parent)
{
setWindowTitle("第一个Qt6窗口");
resize(600, 400);

QLabel* label = new QLabel(this);
label->setText("这是一个标签控件");
label->setGeometry(200, 30, 200, 50);

QPushButton* button = new QPushButton(this);
button->setText("这是一个按钮控件");
button->setGeometry(200, 80, 200, 50);
connect(button, &QPushButton::clicked, this, &MyFirstQt6::onButtonClicked);

QLineEdit* lineEdit = new QLineEdit(this);
lineEdit->setGeometry(200, 130, 200, 50);
}

MyFirstQt6::~MyFirstQt6()
{}

void MyFirstQt6::onButtonClicked()
{
auto res = QMessageBox::information(this, "信息", "按钮被点击了!");
}

相关推荐
hoiii1879 分钟前
CSTR反应器模型的Simulink-PID仿真(MATLAB实现)
开发语言·matlab
卤炖阑尾炎15 分钟前
PostgreSQL 日常运维全指南:从基础操作到备份恢复
运维·数据库·postgresql
炘爚40 分钟前
C++ 右值引用与程序优化
开发语言·c++
handsomestWei1 小时前
Docker引擎API接入配置
运维·http·docker·容器·api
si莉亚1 小时前
ROS2安装EVO工具包
linux·开发语言·c++·开源
Tingjct1 小时前
Linux常用指令
linux·运维·服务器
清心歌1 小时前
CopyOnWriteArrayList 实现原理
java·开发语言
广州灵眸科技有限公司1 小时前
为RK3588注入澎湃算力:RK1820 AI加速卡完整适配与评测指南
linux·网络·人工智能·物联网·算法
daad7771 小时前
wifi_note
运维·服务器·数据库
IT界的老黄牛1 小时前
Linux 压缩命令实战:tar、gzip、bzip2、xz、zstd 怎么选?一篇讲清楚
linux·运维·服务器