Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
ui->logoLabel->setPixmap(QPixmap(":/pictrue/logo.png"));
ui->logoLabel->setScaledContents(true);
ui->actLabel->setPixmap(QPixmap(":/pictrue/wodepeizhenshi.png"));
ui->actLabel->setScaledContents(true);
ui->pwdLabel->setPixmap(QPixmap(":/pictrue/passwd.jpg"));
ui->pwdLabel->setScaledContents(true);
ui->pwdLineEdit->setEchoMode(QLineEdit::Password);
// 手动连接信号和槽
connect(ui->loginButton, SIGNAL(clicked()), this, SLOT(mySlot()));
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_cancelButton_clicked()
{
this->close();
}
void Widget::mySlot()
{
if(ui->actLineEdit->text() == "admin" && ui->pwdLineEdit->text() == "123456")
{
QLabel *successMsg = new QLabel("登录成功", this);
successMsg->move((width()-successMsg->width())/2, ui->loginButton->y() + 40);
successMsg->setStyleSheet("background-color:green; color: white");
// 使label内的字体居中
successMsg->setAlignment(Qt::AlignCenter);
successMsg->resize(100, 30);
// 显示label
successMsg->show();
// 延时关闭窗口
QTimer::singleShot(3000, this, SLOT(closeWindow()));
}
else
{
QLabel *failureMsg = new QLabel("登录失败", this);
failureMsg->move((width()-failureMsg->width())/2, ui->loginButton->y() + 40);
failureMsg->setStyleSheet("background-color:red; color: white");
failureMsg->setAlignment(Qt::AlignCenter);
failureMsg->resize(100, 30);
// 显示错误信息
failureMsg->show();
// 清空账号和密码输入行
ui->actLineEdit->clear();
ui->pwdLineEdit->clear();
}
}
void Widget::closeWindow()
{
this->close();
}