8.14作业
设置窗口,按钮,标签,行编辑器,实现快递速运登录页面
#include "mywidget.h"MyWidget::MyWidget(QWidget *parent): QWidget(parent)
{//=============================窗口=======================//设置窗口的标题this->setWindowTitle("邮递系统");//设置窗口的图标this->setWindowIcon(QIcon("C:\\Users\\ASUS\\Desktop\\picture\\tubiao.png"));//设置窗口背景颜色this->setStyleSheet("background-color:white");//设置窗口大小this->resize(540,415);//固定窗口大小this->setFixedSize(540,415);//设置纯净窗口,去掉头部this->setWindowFlag(Qt::FramelessWindowHint);//=============================标签=======================//创建账号标签QLabel *lab1 = new QLabel(this);//背景颜色lab1->setStyleSheet("background-color:red");//大小lab1->resize(30,30);//移动lab1->move(100,200);//设置图片lab1->setPixmap(QPixmap("C:\\Users\\ASUS\\Desktop\\picture\\userName.jpg"));//设置图片自适应lab1->setScaledContents(true);//创建密码标签QLabel *lab2 = new QLabel(this);//背景颜色lab2->setStyleSheet("background-color:red");//大小lab2->resize(30,30);//移动lab2->move(100,250);//设置图片lab2->setPixmap(QPixmap("C:\\Users\\ASUS\\Desktop\\picture\\passwd.jpg"));//设置图片自适应lab2->setScaledContents(true);//设置头部动图QLabel *lab3 = new QLabel(this);lab3->resize(540,160);//实例化一个动图指针QMovie *mv = new QMovie("C:\\Users\\ASUS\\Desktop\\picture\\feiji.gif");//将动图设置到标签中lab3->setMovie(mv);//让动图动起来mv->start();lab3->setScaledContents(true);//=============================行编辑器=======================//账号行编辑器QLineEdit *edit1 = new QLineEdit(this);//大小edit1->resize(280,30);//移动edit1->move(150,200);//占位edit1->setPlaceholderText("账号");//显示模式edit1->setEchoMode(QLineEdit::Normal);//密码行编辑器QLineEdit *edit2 = new QLineEdit(this);edit2->resize(280,30);edit2->move(150,250);edit2->setPlaceholderText("密码");edit2->setEchoMode(QLineEdit::Normal);//=============================按钮======================//创建按钮QPushButton *btn1 = new QPushButton("登录",this);//大小btn1->resize(315,40);//移动按钮btn1->move(115,310);//设置背景颜色,字体颜色,设置圆角btn1->setStyleSheet("background-color:rgb(31,200,250);color:white;border-radius:5px");
}MyWidget::~MyWidget()
{
}
8.16作业
widget.h
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QMovie>
#include <QString>
#include <QDebug>QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();private:Ui::Widget *ui;
private slots:void login_slot();
};
#endif // WIDGET_H
widget.cpp
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);ui->logoLabel->setPixmap(QPixmap(":/picture/feiji.gif"));ui->logoLabel->setScaledContents(true);//实例化一个动图指针QMovie *mv = new QMovie(":/picture/feiji.gif");//将动图设置到标签中ui->logoLabel->setMovie(mv);//让动图动起来mv->start();ui->usernameLabel->setPixmap(QPixmap(":/picture/login.png"));ui->usernameLabel->setScaledContents(true);ui->passwordLabel->setPixmap(QPixmap(":/picture/passwd.jpg"));ui->passwordLabel->setScaledContents(true);ui->passwordEdit->setEchoMode(QLineEdit::Password);//qt4 不友好的链接connect(ui->cancelButton,SIGNAL(clicked()),this,SLOT(close()));//基于qt5的手动连接,友好的连接connect(ui->LoginButton,&QPushButton::clicked,this,&Widget::login_slot);}Widget::~Widget()
{delete ui;
}void Widget::login_slot()
{if(ui->usernameEdit->text()=="admin" && ui->passwordEdit->text()=="123456"){qDebug() << "登录成功";this->close();}else{qDebug() << "登录失败";ui->passwordEdit->clear();}
}