day1 QT c++ c语言学习

写了一个类似qq的窗口

头文件

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QDebug>
#include <QIcon>
#include <QFile>
#include <QTextStream>
#include <QPushButton>
#include <QLineEdit>
#include <QLabel>
#include <QCheckBox>
#include <QPropertyAnimation>

class Widget : public QWidget
{

private:
    Q_OBJECT

public slots:
    void exit_app();

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
    QLabel *label_logo;
    QPushButton *button1;
    QPushButton *button2;
    QLineEdit *line_edit1;
    QLineEdit *line_edit2;
    QLabel *label1;
    QLabel *label1_1;
    QLabel *label2;
    QLabel *label2_2;
    QCheckBox *check_box1;
    QCheckBox *check_box2;
    QPropertyAnimation *animation_button1;

};

#endif // WIDGET_H

main.cpp

#include "widget.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    Widget w;
    w.show();

    return a.exec();
}


widget.cpp

#include "widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{


    this->setFixedSize(600,450);
    qDebug("%d",this->width());
    qDebug("%d",this->height());

    this->setWindowIcon(QIcon("D:\\QtProjects\\Qproject2\\thinking_128.ico"));
    this->setWindowTitle("Jingyi's App");

    QFile file("D:\\华清远见\\QSS-master\\QSS-master\\MacOs.qss");
    file.open(QFile::ReadOnly);
    QTextStream filetext(&file);
    QString stylesheet = filetext.readAll();
    this->setStyleSheet(stylesheet);
    file.close();

    label_logo = new QLabel(this);
    label_logo->setGeometry(0,0,0,0);
    label_logo->resize(600,240);
    label_logo->setScaledContents(true);
    label_logo->setPixmap(QPixmap("C:\\Users\\Administrator\\Downloads\\background_pics\\Awake.png"));

    animation_button1 = new QPropertyAnimation();
    animation_button1->setEasingCurve(QEasingCurve::Linear);
    animation_button1->setTargetObject(this);
    animation_button1->setPropertyName("windowOpacity");
    animation_button1->setDuration(2000);
    animation_button1->setKeyValueAt(0, 0);
    animation_button1->setKeyValueAt(0.5, 0.5);
    animation_button1->setKeyValueAt(1, 1);
    animation_button1->setLoopCount(1);
    animation_button1->start();

    button1 = new QPushButton();
    button1->setParent(this);
    button1->setGeometry(100,400,0,0);
    button1->resize(160,40);
    button1->setText("Log in");


    button2 = new QPushButton(this);
    button2->setParent(this);
    button2->setGeometry(300,400,0,0);
    button2->resize(160,40);
    button2->setText("Quit");
    connect(button2, SIGNAL(clicked()), this, SLOT(exit_app()));
    //connect(button2, &QPushButton::clicked, this, &Widget::exit_app);

    line_edit1 = new QLineEdit(this);
    line_edit1->setGeometry(200,250,0,0);
    line_edit1->resize(320,40);
    line_edit1->setPlaceholderText("Username");

    line_edit2 = new QLineEdit(this);
    line_edit2->setGeometry(200,300,0,0);
    line_edit2->resize(320,40);
    line_edit2->setEchoMode(QLineEdit::Password);
    line_edit2->setPlaceholderText("Password");

    label1 = new QLabel(this);
    label1->setGeometry(50,250,0,0);
    label1->resize(120,40);
    label1->setText("Username:");

    label1_1 = new QLabel(this);
    label1_1->setGeometry(140,250,0,0);
    label1_1->resize(40,40);
    label1_1->setPixmap(QPixmap("D:\\QtProjects\\Qproject2\\user_24px.ico"));

    label2 = new QLabel(this);
    label2->setGeometry(50,300,0,0);
    label2->resize(120,40);
    label2->setText("Password:");

    label2_2 = new QLabel(this);
    label2_2->setGeometry(140,300,0,0);
    label2_2->resize(40,40);
    label2_2->setPixmap(QPixmap("D:\\QtProjects\\Qproject2\\lock_24px.ico"));

    check_box1 = new QCheckBox(this);
    check_box1->setGeometry(50,350,0,0);
    check_box1->resize(200,40);
    check_box1->setText("Forget password:");

    check_box2 = new QCheckBox(this);
    check_box2->setGeometry(250,350,0,0);
    check_box2->resize(200,40);
    check_box2->setText("Always logged in:");

}

Widget::~Widget()
{
    delete animation_button1;
}

void Widget::exit_app()
{
    this->close();
}

 两个素材图片:

 

一个背景图:

 太大了不让上传,自己去deviantart找

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值