作业1:
#include "mywidget.h"
MyWidget::MyWidget(QWidget *parent)
: QMainWindow(parent)
{
this->setWindowTitle("顶针的瑞克五代专卖店");
this->setWindowIcon(QIcon(":/pictrue/icon.png"));
this->setWindowFlags(Qt::FramelessWindowHint);
this->resize(550,530);
this->setStyleSheet("background-color:white");
QLabel *lab1 = new QLabel(this);
lab1->resize(550,250);
QMovie *gif = new QMovie(":/pictrue/gif.jpg");
lab1->setMovie(gif);
gif->start();
lab1->setScaledContents(true);
QLabel *lab2 = new QLabel(this);
lab2->setText("账号");
lab2->resize(40,40);
lab2->move(110,260);
QLabel *lab3 = new QLabel(this);
lab3->resize(40,40);
lab3->move(110,300);
lab3->setPixmap(QPixmap(":/pictrue/1.png"));
lab3->setScaledContents(true);
QLineEdit *edit1 = new QLineEdit(this);
edit1->resize(160,40);
edit1->move(150,300);
edit1->setPlaceholderText("username");
QLineEdit *edit2 = new QLineEdit(this);
edit2->resize(160,40);
edit2->move(150,380);
edit2->setPlaceholderText("password");
edit2->setEchoMode(QLineEdit::Password);
QLabel *lab4 = new QLabel(this);
lab4->setText("密码");
lab4->resize(40,40);
lab4->move(110,340);
QLabel *lab5 = new QLabel(this);
lab5->resize(40,40);
lab5->move(110,380);
lab5->setPixmap(QPixmap(":/pictrue/2.png"));
lab5->setScaledContents(true);
QPushButton *btn1 = new QPushButton(this);
btn1->resize(160,60);
btn1->move(130,440);
btn1->setText("Login");
btn1->setStyleSheet("background-color:blue;border-radius:3px");
}
MyWidget::~MyWidget()
{
}
作业2:
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
,login_btn(new QPushButton("login",this))
{
ui->setupUi(this);
login_btn->resize(151,71);
login_btn->move(210,290);
ui->username_lineEdit->setPlaceholderText("plz enter username");
ui->password_lineEdit->setPlaceholderText("plz enter password");
ui->password_lineEdit->setEchoMode(QLineEdit::Password);
connect(login_btn,SIGNAL(clicked()),this,SLOT(login_slot()));
}
Widget::~Widget()
{
delete login_btn;
delete ui;
}
void Widget::login_slot()
{
if(ui->username_lineEdit->text() == "admin" && ui->password_lineEdit->text() == "123456")
{
qInfo() << "login successfully!";
close();
}
else
{
qInfo() << "username or password error!";
ui->password_lineEdit->clear();
}
}
void Widget::on_cannel_pushButton_clicked()
{
close();
}