qt设计一个登录界面
时间: 2023-08-14 20:11:00 浏览: 46
好的,下面是一个简单的登录界面的Qt代码:
```cpp
#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.setWindowTitle("登录");
QLabel *usernameLabel = new QLabel("用户名:", &window);
QLineEdit *usernameLineEdit = new QLineEdit(&window);
QLabel *passwordLabel = new QLabel("密码:", &window);
QLineEdit *passwordLineEdit = new QLineEdit(&window);
QPushButton *loginButton = new QPushButton("登录", &window);
// 设置布局
QHBoxLayout *usernameLayout = new QHBoxLayout;
usernameLayout->addWidget(usernameLabel);
usernameLayout->addWidget(usernameLineEdit);
QHBoxLayout *passwordLayout = new QHBoxLayout;
passwordLayout->addWidget(passwordLabel);
passwordLayout->addWidget(passwordLineEdit);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(usernameLayout);
mainLayout->addLayout(passwordLayout);
mainLayout->addWidget(loginButton);
window.setLayout(mainLayout);
window.show();
return app.exec();
}
```
这个代码创建了一个窗口,窗口标题为“登录”,包含了两个文本框和一个按钮。你可以根据需要进一步美化这个界面,请注意这只是一个简单的示例。