Qt作业合集

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_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    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();
    }
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用内容可以得知,白夜黑羽是一个提供Python Qt图形界面编程学习的视频网站,视频中介绍了如何使用PyQt5进行图形界面编程以及如何封装exe文件,适合初学者学习。 而根据引用内容,白夜黑羽在家参考相关博文、视频和代码等学习了PyQt5的基础知识,并尝试为YOLOV5添加界面。通过简单的Demo项目记录了学习过程,并供自己交流学习使用。 所以,结合以上内容可以得知,白夜黑羽的Python Qt作业是通过学习PyQt5基础知识,尝试为YOLOV5添加界面,并通过一个简单的Demo项目记录学习过程和交流学习。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Python Qt 图形界面编程 - 白月黑羽(小班代码大全打包).zip](https://download.csdn.net/download/zzx188891020/12367810)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [使用PyQt5为YoloV5添加界面(一)](https://blog.csdn.net/wrh975373911/article/details/119322059)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值