创建文本框控件

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

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, "信息", "按钮被点击了!");
}

相关推荐
Gauss松鼠会3 分钟前
【GaussDB】GaussDB 组件、节点和AZ故障仲裁与切换流程
运维·服务器·数据库·gaussdb
飘忽不定的bug10 分钟前
ubuntu20.04交叉编译QT5.15.12(RK3562+ubuntu20.04)
linux·qt·ubuntu
weixin_4407305015 分钟前
使用pytest中方法控制执行步骤(test_begin.py、test_end.py,@pytest.mark.run(order=1))
开发语言·python·pytest
库玛西19 分钟前
深入浅出Linux select网络模型:从底层位图原理到C++面向对象高级封装
linux·服务器·网络·c++·ubuntu
Tingjct21 分钟前
线程详细讲解---聚焦linux
linux·服务器·jvm
数字孪生视频孪生34 分钟前
空间智能技术|跨镜轨迹全域可溯,无感定位无扰赋能落地
大数据·运维·人工智能·重构·架构
ComputerInBook36 分钟前
linux包管理工具——yum(YellowdogUpdaterModified)
linux·运维·服务器·yum·dnf
霸道流氓气质41 分钟前
通义千问 Chat 模型高级用法:Function Calling / Structured Output / 多轮对话
linux·运维·windows
en.en..42 分钟前
Linux mmap 内存映射深度解析:基于帧缓冲 /dev/fb0
java·服务器·前端
geovindu43 分钟前
CSharp: Command Pattern
开发语言·后端·c#·.net·.netcore·命令模式·行为模式