C++作业

 

 

 

 

结果实现

 

widget.cpp

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

  this->setWindowTitle("QQ");
    //更改窗口图标
 this->setWindowIcon(QIcon("D:\\qt\\qt\\day2\\ipng.JPG"));
    QLabel *lab2 =new QLabel ("标签1",this);
   //lab2->move(20,100);
    lab2->resize(900,200);//重新设置大小
    lab2->setScaledContents(true);//设置内容自适应大小
    lab2->setPixmap(QPixmap("D:\\qt\\qt\\day2\\02_class\\icon\\icon\\LOGO1.png"));
    //设置透明度
     //this->setWindowOpacity(0.5);

    QLabel *lab3 =new QLabel ("标签2",this);
      lab3->move(100,200);
    lab3->resize(50,30);//重新设置大小
    lab3->setScaledContents(true);//设置内容自适应大小
    lab3->setPixmap(QPixmap("D:\\qt\\qt\\day2\\02_class\\icon\\icon\\zhanghao.png"));

    QLabel *lab4 =new QLabel ("标签2",this);
      lab4->move(100,250);
    lab4->resize(50,30);//重新设置大小
    lab4->setScaledContents(true);//设置内容自适应大小
    lab4->setPixmap(QPixmap("D:\\qt\\qt\\day2\\02_class\\icon\\icon\\denglumima.png"));

    edit2 =new QLineEdit ("请输入",this);
    edit2->resize(300,30);
    edit2->move(160,250);
    edit2->resize(300,30);
    //ui->edit1->resize(300,30);
    //设置文本内容回显模式
    edit2->setEchoMode(QLineEdit::Password);
    //设置行编辑器占位符
    ui->edit1->setPlaceholderText("账号");
    //设置行编辑器占位符
    edit2->setPlaceholderText("密码");
    //获取文本内容
    QString msg =edit2->text();
    qDebug()<<msg;
    //清除文本内容
    edit2->clear();
   QRadioButton *button1=new QRadioButton("自动登录",this);
     button1->move(180,290);
   button1->setText("忘记密码");
    QRadioButton *button2=new QRadioButton("自动登录",this);
    button2->move(300,290);
    button2->setText("自动登录");

    push1=new QPushButton("登录",this);
    push1->move(200,330);
     push1->resize(50,30);//重新设置大小

     push2=new QPushButton("取消",this);

    push2->move(300,330);
    push2->resize(50,30);//重新设置大小
    connect(push1,SIGNAL(clicked()),this,SLOT(my_slot()));
    connect(push2, SIGNAL(clicked()), this, SLOT(my_delete()));

}

Widget::~Widget()
{
    delete ui;
}
//登录槽函数的实现
void Widget::my_slot()
{
    //书写相关逻辑
    QString name;
    QString pwd;
   name = ui->edit1->text();//比较账号
   pwd = edit2->text();//比较密码
   if(name=="admin"&&pwd=="123456")
   {
       qDebug("登录成功\n");
       this->close();//关闭
   }else if(name!="admin"||pwd!="123456")
   {
       qDebug("账号和密码不匹配,请重新输入\n");
       edit2->clear();
   }
}

//取消槽函数实现
void Widget::my_delete()
{
    this->close();//关闭
}

 widget.h

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值