QTDay3

思维导图

复制代码
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //==============窗口相关设置=======
        this->resize(540,415);
        this->setFixedSize(540,415);
        //窗口标题
        this->setWindowTitle("盗版QQ");
        //窗口图标
        this->setWindowIcon(QIcon("C:/Users/abcd/Desktop/pictrue/qq"));
        //背景颜色
        this->setStyleSheet("background-color:white");
        //去掉头部
        this->setWindowFlag(Qt::FramelessWindowHint);


        //============标签相关设置=======
        QLabel *lab1 = new QLabel(this);
        //设置大小
        lab1->resize(540, 160);
        lab1->setStyleSheet("background-color:pink");
        //动图类 接收动图
        QMovie *mv = new QMovie("C:/Users/abcd/Desktop/pictrue/zz.gif");
        //将动图放入标签中
        lab1->setMovie(mv);
        //让动图动起来
        mv->start();
        //自动适应
        lab1->setScaledContents(true);


        QLabel *lab2 = new QLabel(this);
        lab2->resize(30,30);
        lab2->move(120,210);
        lab2->setPixmap(QPixmap("C:/Users/abcd/Desktop/pictrue/shi"));
        lab2->setScaledContents(true);

        QLabel *lab3 = new QLabel(this);
        lab3->resize(30,30);
        lab3->move(120, 260);
        lab3->setPixmap(QPixmap("C:/Users/abcd/Desktop/pictrue/passwd"));
        lab3->setScaledContents(true);


        //============行编辑器相关设置=======
        QLineEdit *edit1 = new QLineEdit(this);
        edit1->resize(275,30);
        edit1->move(155,210);
        edit1->setPlaceholderText("QQ号/手机号/邮箱");


         QLineEdit *edit2 = new QLineEdit(this);
         edit2->resize(275,30);
         edit2->move(155,260);
         edit2->setPlaceholderText("密码");
         edit2->setEchoMode(QLineEdit::Password);

         //============按钮相关设置=======
          QPushButton *btn = new QPushButton("登录",this);
          btn->resize(300,45);
          btn->move(120,345);
          //样式函数setStyleSheet()
          btn->setStyleSheet("background-color:rgb(8,189,253);border-radius:5px;color:white");
          connect(btn,&QPushButton::clicked,this,&Widget::btn_clicked);

}

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

void Widget::btn_clicked()
{
        if(this->edit1->text()=="Admin"&&this->edit2->text()=="123456")
        {
            QMessageBox box(QMessageBox::Question,
                      "消息对话框",
                       "登录成功",
                       QMessageBox::Ok|QMessageBox::No,
                      this);
       int res=box.exec();
       if(res==QMessageBox::Ok)
       {
       this->close();
       }
       }
        else
        {
            QMessageBox box(QMessageBox::Question,
                      "错误对话框",
                       "登录失败",
                       QMessageBox::Ok|QMessageBox::No,
                      this);
            int res1=box.exec();
            if(res1==QMessageBox::Ok)
            {
                this->edit1->clear();
                this->edit2->clear();
            }else if(res1==QMessageBox::No)
            {
                this->close();
            }
         }
}

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

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


void Widget::on_fontBtn_clicked()
{
    bool ok=false;
    QFont f=QFontDialog::getFont(&ok,
                                 QFont("宋体",10,10,true),
                                 this,
                                 "选择字体");

   if(ok)
 {
    ui->textEdit->setCurrentFont(f);

 }
}
void Widget::on_colorBtn_clicked()
{
    QColor c=QColorDialog::getColor(QColor("red"),
                                    this,
                                    "选择颜色");
    if(c.isValid()==true)
    {
        ui->textEdit->setTextBackgroundColor(c);
    }
}


void Widget::on_openFileBtn_clicked()
{
    QString FileName=QFileDialog::getOpenFileName(this,
                                                  "选择文件",
                                                  "./",
                                                  "all(*.*);;images(*.png *.jpg *.gif);;源文件(*.cpp)");
    qDebug()<<FileName;
    QFile file(FileName);
    if(file(QFile::ReadOnly)==false)
    {
        QMessageBox::information(this,"提示","文件打开失败");
        return;
    }
    QByteArray msg=file.readAll();
    ui->textEdit->setText(msg);
    file.close();
}
相关推荐
微学AI2 小时前
一根针指向所有方向:挂谷猜想对 LLM Agent 技能-记忆架构的启示
开发语言·人工智能·架构·挂谷猜想
豆瓣鸡2 小时前
算法日记 - Day3
java·开发语言·算法
韭菜炒鸡肝天3 小时前
VTK开发笔记(一):VTK介绍,Qt..+VSx+VTK.编译
开发语言·笔记·qt
Aaron - Wistron3 小时前
Web API C# (Furion版)带 单元测试
开发语言·后端·c#
Dxy12393102164 小时前
Python项目打包成EXE完整教程(PyInstaller实战避坑)
开发语言·python
0566465 小时前
Python康复训练——常用标准库
开发语言·python·学习
骊城英雄5 小时前
基于C#+avalonia ui实现的跨平台点胶机灌胶监控控制上位机软件
开发语言·ui·c#
吾儿良辰5 小时前
一个被BCL遗忘的高性能集合:C# CircularBuffer<T>深度解析
开发语言·windows·c#
昆曲之源_娄江河畔5 小时前
Python如何安装flask, pymssql
开发语言·python·flask·pymssql
Leighteen6 小时前
`try-finally` 里的 `return`:为什么 `finally` 会悄悄改掉返回值、吞掉异常
java·开发语言