用qt实现用户名输入框、密码输入框、登录和取消按钮的源代码
时间: 2023-05-21 09:03:00 浏览: 513
以下是用Qt实现用户名输入框、密码输入框、登录和取消按钮的源代码:
```cpp
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// 创建主窗口
QWidget *mainWindow = new QWidget;
mainWindow->setWindowTitle("登录");
// 创建用户名输入框
QLabel *userLabel = new QLabel("用户名:");
QLineEdit *userEdit = new QLineEdit;
// 创建密码输入框
QLabel *passwordLabel = new QLabel("密码:");
QLineEdit *passwordEdit = new QLineEdit;
passwordEdit->setEchoMode(QLineEdit::Password);
// 创建登录和取消按钮
QPushButton *loginButton = new QPushButton("登录");
QPushButton *cancelButton = new QPushButton("取消");
// 创建布局
QGridLayout *layout = new QGridLayout;
layout->addWidget(userLabel, 0, 0);
layout->addWidget(userEdit, 0, 1);
layout->addWidget(passwordLabel, 1, 0);
layout->addWidget(passwordEdit, 1, 1);
layout->addWidget(loginButton, 2, 0);
layout->addWidget(cancelButton, 2, 1);
// 设置布局
mainWindow->setLayout(layout);
// 显示主窗口
mainWindow->show();
return app.exec();
}
```
希望这个代码能够帮助你实现你的需求。