创建文本框控件

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

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

相关推荐
xcyxiner16 小时前
DicomViewer (后台线程处理文件)4
qt
用户03284722207016 小时前
如何搭建本地yum源(上)
运维
xcyxiner1 天前
DicomViewer (添加模型类)3
qt
xcyxiner2 天前
DicomViewer (目录调整) 2
qt
A小辣椒2 天前
TShark:Wireshark CLI 功能
linux
xcyxiner2 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
A小辣椒2 天前
TShark:基础知识
linux
AlfredZhao2 天前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao3 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334663 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux