一个基于QT简单登录对话框

时间:2022-03-12 17:13:39

1. 登录对话框式样

一个基于QT简单登录对话框

2. QLoginDialog.h

#ifndef DIALOG_H
#define DIALOG_H #include <QtGui/QDialog>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit> class QLoginDialog : public QDialog
{
Q_OBJECT
private:
QLabel UserLable;
QLabel PwdLable;
QPushButton CancelBtn;
QPushButton LoginBtn;
QLineEdit UserLineEdit;
QLineEdit PwdLineEdit;
QString m_user;
QString m_pwd;
private slots:
void CancelBtn_Clicked();
void LoginBtn_Clicked();
public:
QLoginDialog(QWidget *parent = );
QString GetUser();
QString GetPwd();
~QLoginDialog();
}; #endif // DIALOG_H

3. QLoginDialog.cpp

#include <QDebug>
#include "QLoginDialog.h" QLoginDialog::QLoginDialog(QWidget *parent) : QDialog(parent, Qt::WindowCloseButtonHint),
UserLable(this), PwdLable(this), CancelBtn(this), LoginBtn(this),UserLineEdit(this), PwdLineEdit(this)
{
UserLable.setText("User Name");
UserLable.move(, );
UserLable.resize(, ); UserLineEdit.move(, );
UserLineEdit.resize(, ); PwdLable.setText("Password");
PwdLable.move(, );
PwdLable.resize(, ); PwdLineEdit.move(, );
PwdLineEdit.resize(, );
PwdLineEdit.setEchoMode(QLineEdit::Password); CancelBtn.setText("Cancel");
CancelBtn.move(, );
CancelBtn.resize(, ); LoginBtn.setText("Login");
LoginBtn.move(, );
LoginBtn.resize(, ); setWindowTitle("Login");
setFixedSize(, ); connect(&CancelBtn, SIGNAL(clicked()), this, SLOT(CancelBtn_Clicked()));
connect(&LoginBtn, SIGNAL(clicked()), this, SLOT(LoginBtn_Clicked())); }
void QLoginDialog::CancelBtn_Clicked()
{
qDebug("CancelBtn_Clicked start"); done(Rejected); qDebug("CancelBtn_Clicked end");
}
void QLoginDialog::LoginBtn_Clicked()
{
qDebug("LoginBtn_Clicked start"); m_user = UserLineEdit.text().trimmed();//trimmed():Delete space
m_pwd = PwdLineEdit.text(); done(Accepted); qDebug("LoginBtn_Clicked end");
} QString QLoginDialog::GetUser()
{
return m_user;
}
QString QLoginDialog::GetPwd()
{
return m_pwd;
} QLoginDialog::~QLoginDialog()
{ }