qt登录界面
时间: 2023-06-29 07:05:41 浏览: 49
以下是一个简单的 Qt 登录界面的示例代码:
```
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.setWindowTitle("登录");
QLabel *usernameLabel = new QLabel("用户名:");
QLineEdit *usernameLineEdit = new QLineEdit;
QHBoxLayout *usernameLayout = new QHBoxLayout;
usernameLayout->addWidget(usernameLabel);
usernameLayout->addWidget(usernameLineEdit);
QLabel *passwordLabel = new QLabel("密码:");
QLineEdit *passwordLineEdit = new QLineEdit;
passwordLineEdit->setEchoMode(QLineEdit::Password);
QHBoxLayout *passwordLayout = new QHBoxLayout;
passwordLayout->addWidget(passwordLabel);
passwordLayout->addWidget(passwordLineEdit);
QPushButton *loginButton = new QPushButton("登录");
QPushButton *cancelButton = new QPushButton("取消");
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addWidget(loginButton);
buttonLayout->addWidget(cancelButton);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(usernameLayout);
mainLayout->addLayout(passwordLayout);
mainLayout->addLayout(buttonLayout);
window.setLayout(mainLayout);
window.show();
return app.exec();
}
```
这个示例创建了一个包含用户名、密码和登录/取消按钮的窗口,其中密码框使用了 `setEchoMode` 函数来隐藏输入的文本。您可以根据自己的需要对其进行修改。