QTday10

键盘事件

void Widget::keyPressEvent(QKeyEvent *event)
{
   // qDebug() << "键盘被按下"<text()<<"  键值为"<key();
    switch(event->key())
    {

    case 'W':
    {
        if(ui->label->y() <= 0-ui->label->height())
        {
            ui->label->move(ui->label->x(),this->height());
        }
         ui->label->move(ui->label->x(),ui->label->y()-5);
         break;
    }

    case 'S':
    {
        if(ui->label->y() >= this->height())
        {
            ui->label->move(ui->label->x(),-ui->label->height());
        }
         ui->label->move(ui->label->x(),ui->label->y()+5);
         break;
    }

    case 'A':
    {
        if(ui->label->x() <= -ui->label->width())
        {
            ui->label->move(this->width(),ui->label->y());
        }
         ui->label->move(ui->label->x()-5,ui->label->y());
         break;
    }

    case 'D':
    {
        if(ui->label->x() >= this->width())
        {
            ui->label->move(-ui->label->width(),ui->label->y());
        }
         ui->label->move(ui->label->x()+5,ui->label->y());
         break;
    }


    }



}

登录页面

//登录按钮连接的槽函数
void Widget::my_slot1()
{
    if(this->edit1->text()=="admin"&&this->edit2->text()=="123")
    {
        QMessageBox box(QMessageBox::Information,
                        "正确",
                        "登录成功",
                        QMessageBox::Ok,
                        this);
        int n=box.exec();
        if(n==QMessageBox::Ok)
        {
            emit jump1();//跳转信号
            this->close();
        }

    }
    else
    {

         QMessageBox box(QMessageBox::Critical,
                         "错误",
                         "账号密码不匹配,是否重新登录?",
                         QMessageBox::Ok|QMessageBox::Cancel,
                         this);
         int n=box.exec();
         if(n==QMessageBox::Ok)
         {
             edit1->clear();
             edit2->clear();
         }

    }
}

//取消按钮连接的槽函数
void Widget::my_slot2()
{
    QMessageBox box(QMessageBox::Question,
                    "取消",
                    "是否要退出登录?",
                    QMessageBox::Yes|QMessageBox::No,
                    this);
    int n=box.exec();
    if(n==QMessageBox::Yes)
    {
        this->close();
    }
    else
    {
        edit1->clear();
        edit2->clear();
    }
}

你可能感兴趣的:(javascript,开发语言,ecmascript)