作业:自由发挥应用场景 实现登录界面
代码:
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QIcon>
#include <QLabel>
#include <QMovie>
#include <QLineEdit>
#include <QPushButton>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
};
#endif // MAINWINDOW_H
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
//********************窗口相关设置***********************
this->setWindowTitle("QQ登录");
this->setWindowIcon(QIcon("C:/Users/lenovo/Desktop/qq.png"));
this->resize(540,410);
//设置纯净窗口,去掉头部
this->setWindowFlag(Qt::FramelessWindowHint);
//设置背景颜色
this->setStyleSheet("background-color:white");
//*****************标签相关设置****************************
//第一个标签
QLabel *lab1 = new QLabel(this);
lab1->move(0,170);
lab1->resize(540,240);
lab1->setStyleSheet("background-color:blue");
QMovie *mv1 = new QMovie("C:\\Users\\lenovo\\Desktop\\Ash.gif");
lab1->setMovie(mv1);
mv1->start();
lab1->setScaledContents(true);
//第二个标签
QLabel *lab2 = new QLabel(this);
lab2->resize(540,170);
lab2->setPixmap(QPixmap("C:\\Users\\lenovo\\Desktop\\DS.png"));
lab2->setScaledContents(true);
//第三个标签
QLabel *lab3 = new QLabel(this);
lab3->move(130,220);
lab3->resize(20,20);
lab3->setPixmap(QPixmap("C:\\Users\\lenovo\\Desktop\\userName.jpg"));
lab3->setScaledContents(true);
//第四个标签
QLabel *lab4 = new QLabel(this);
lab4->move(130,250);
lab4->resize(20,20);
lab4->setPixmap(QPixmap("C:\\Users\\lenovo\\Desktop\\passwd.jpg"));
lab4->setScaledContents(true);
//第五个标签
QLabel *lab5 = new QLabel(this);
lab5->move(20,20);
lab5->resize(60,40);
lab5->setPixmap(QPixmap("C:\\Users\\lenovo\\Desktop\\R-C.jpg"));
lab5->setScaledContents(true);
//第六个标签
QLabel *lab6 = new QLabel(this);
lab6->move(510,0);
lab6->resize(30,30);
lab6->setPixmap(QPixmap("C:\\Users\\lenovo\\Desktop\\cancel.png"));
lab6->setScaledContents(true);
QLabel *lab7 = new QLabel(this);
lab7->move(150,280);
lab7->resize(50,15);
lab7->setText("自动登录");
QLabel *lab8 = new QLabel(this);
lab8->move(270,280);
lab8->resize(50,15);
lab8->setText("自动登录");
QLabel *lab9 = new QLabel(this);
lab9->move(380,280);
lab9->resize(50,15);
lab9->setText("自动登录");
//***********************行编辑类相关设置**************************
QLineEdit *edit1 = new QLineEdit(this);
edit1->move(150,220);
edit1->resize(280,20);
edit1->setPlaceholderText("账号");
QLineEdit *edit2 = new QLineEdit(this);
edit2->move(150,250);
edit2->resize(280,20);
edit2->setPlaceholderText("密码");
edit2->setEchoMode(QLineEdit::Password);
//**********************按钮相关操作******************
QPushButton *btn1 = new QPushButton(this);
btn1->setText("登录");
btn1->move(130,360);
btn1->resize(300,45);
btn1->setStyleSheet("background-color:skyblue;border-radius:10px");
QPushButton *btn2 = new QPushButton(this);
btn2->setText(" ");
btn2->move(130,280);
btn2->resize(15,15);
btn2->setStyleSheet("border-radius:10px");
QPushButton *btn3 = new QPushButton(this);
btn3->setText(" ");
btn3->move(250,280);
btn3->resize(15,15);
btn3->setStyleSheet("border-radius:10px");
}
MainWindow::~MainWindow()
{
}
运行结果: