C++ day2

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();
}

 

相关推荐

  1. MSc CDA Take-Home

    2024-06-15 02:24:03       33 阅读
  2. CDA一级备考策略分享

    2024-06-15 02:24:03       10 阅读
  3. CDA-LevelⅡ【考题整理-带答案】

    2024-06-15 02:24:03       21 阅读
  4. Spring Data访问Elasticsearch----CDI集成

    2024-06-15 02:24:03       17 阅读
  5. CDA Level Ⅰ 2023认证考试大纲

    2024-06-15 02:24:03       15 阅读
  6. web server apache tomcat11-33-CDI

    2024-06-15 02:24:03       10 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-15 02:24:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-15 02:24:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-15 02:24:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-15 02:24:03       18 阅读

热门阅读

  1. Day35

    Day35

    2024-06-15 02:24:03      6 阅读
  2. 怎样为Django的server配置跨域资源共享(CORS)

    2024-06-15 02:24:03       9 阅读
  3. 数据分批处理

    2024-06-15 02:24:03       7 阅读
  4. 手写实现防抖

    2024-06-15 02:24:03       8 阅读
  5. QT的QScopedPointer

    2024-06-15 02:24:03       7 阅读