Qt-写一个模版出来

简介: Qt-写一个模版出来

为啥要写一个模版了,原因就是有到多需要用到了,哈哈哈哈。


是这样滴,一套模拟器上面会有N多个设备,这些设备相互联合又相互独立工作。我呢,需要给每个设备多写一个配置工具,最后需要把这些工具整理成一套系统的配置工具。所以,每个配置工具除了内容不同,界面风格应该相同的,就有这个模版了。



万恶的CSDN穿图片的大小还是不可以太大,只能贴截图了。image.png

第一个是系统的启动动画,这个有点大 ,没法预览,制作方式

1. 网上找好看的AE特效模版

2. 把自己的内容替换上去

3. 导出视屏

4. 用PR转成GIF

这样就可了

至于真么加载这个动画,看代码

#include "mainwindow.h"
#include <QApplication>
#include <QSplashScreen>
#include <QPixmap>
#include <QLabel>
#include <QMovie>
#include <QThread>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QPixmap pixmap("./images/login.gif");
    QSplashScreen splash(pixmap);
    QMovie *movie = new QMovie("./images/login.gif");
    QLabel *label = new QLabel(&splash);
    label->setMovie(movie);
    movie->start();
    splash.show();
    for(int i = 0;i<11000;i+=movie->speed())
    {
        QCoreApplication::processEvents();
        QThread::usleep(500*movie->speed());
    }
    a.setStyleSheet("QLineEdit {border-radius: 4px;height: 25px;border: 1px solid rgb(100, 100, 100);background: rgb(72, 72, 73);}"
                    "QLineEdit:enabled {color: rgb(175, 175, 175);}"
                    "QLineEdit:enabled:hover, QLineEdit:enabled:focus {color: rgb(230, 230, 230);}"
                    "QLineEdit:!enabled {color: rgb(155, 155, 155);}"
                    "QPushButton{border-radius: 4px;border: none;width: 75px;height: 25px;}"
                    "QPushButton:enabled {background: rgb(68, 69, 73);color: white;}"
                    "QPushButton:!enabled {background: rgb(100, 100, 100);color: rgb(200, 200, 200);}"
                    "QPushButton:enabled:hover{background: rgb(85, 85, 85);}"
                    "QPushButton:enabled:pressed{background: rgb(80, 80, 80);}"
                    //关闭按钮样式
                    "QPushButton#pushButton_close{border-radius: 0px;background: rgb(0,0,0,0,);border-image:url(./images/close_n.png);}"
                    "QPushButton::hover#pushButton_close{border-image:url(./images/close_p.png);}"
                    "QPushButton::pressed #pushButton_close{border-image:url(./images/close_n.png);}"
                    //最小化按钮样式
                    "QPushButton#pushButton_min{border-radius: 0px;background: rgb(0,0,0,0,);border-image:url(./images/min_n.png);}"
                    "QPushButton::hover#pushButton_min{border-image:url(./images/min_p.png);}"
                    "QPushButton::pressed #pushButton_min{border-image:url(./images/min_n.png);}"
                    //关于按钮样式
                    "QPushButton#pushButton_about{border-radius: 0px;background: rgb(0,0,0,0,);border-image:url(./images/about_n.png);}"
                    "QPushButton::hover#pushButton_about{border-image:url(./images/about_p.png);}"
                    "QPushButton::pressed #pushButton_about{border-image:url(./images/about_n.png);}"
                    "QLabel {color: rgb(175, 175, 175);}"
                    );
    MainWindow w;
    w.show();
    splash.finish(&w);
    return a.exec();
}

中间有部分是样式表,自动忽略就好

image.png

上面的这个图画就是我的基本模版了,

做了一下工作

1. 隐藏了原有的标题栏

2. 左上角增加了图标和标题

3. 右上角增加了关于、最小化和关闭按钮

4. 限制了鼠标点击点击区域

上下的看代码

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QNetworkDatagram>
#include <QMessageBox>
#include <windows.h>
#include <QDebug>
/*
 * 设定标题栏宽度
 * 后面鼠标事件会用到
 */
const int TITLE_HEIGHT = 30;
/*
 * 构造函数
 */
MainWindow::MainWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setWindowFlag(Qt::FramelessWindowHint);
    this->setWindowIcon(QIcon("./images/logo.ico"));
    ui->pushButton_about->setToolTip("关于我们");
    ui->pushButton_close->setToolTip("关闭");
    ui->pushButton_min->setToolTip("最小化");
    ui->label_ICON->setStyleSheet("QLabel{border-image:url(./images/logo.ico);}");
    ui->label_title->setStyleSheet("QLabel{color: rgb(255, 255, 255);border:0px;}");
    ui->label_title->setText("M1J1DNT701");
}
/*
 * 析构函数
 */
MainWindow::~MainWindow()
{
    delete ui;
}
/*
 * 绘制背景
 */
void MainWindow::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter_back(this);
    painter_back.drawPixmap(0,0,this->width(),this->height(),QPixmap("./images/mainback.png"));
}
//存放当前鼠标位置函数
static QPoint last(0,0);
/*
 * 鼠标按下函数
 */
void MainWindow::mousePressEvent(QMouseEvent *event)
{
    if(event->y()< TITLE_HEIGHT)
    {
        last = event->globalPos();
    }
}
/*
 * 鼠标移动函数
 */
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
    if(event->y() < TITLE_HEIGHT)
    {
        int dx = event->globalX() - last.x();
        int dy = event->globalY() - last.y();
        last = event->globalPos();
        this->move(x()+dx,y()+dy);
    }
}
/*
 * 鼠标释放函数
 */
void MainWindow::mouseReleaseEvent(QMouseEvent *event)
{
    if(event->y() < TITLE_HEIGHT)
    {
        int dx = event->globalX() - last.x();
        int dy = event->globalY() - last.y();
        this->move(x()+dx,y()+dy);
    }
}
/*
 * 关闭按钮槽函数
 */
void MainWindow::on_pushButton_close_clicked()
{
    this->close();
}

好了,暂时就这些


目录
相关文章
|
设计模式 前端开发 算法
QT5——模版库、工具类及控件(下)
QT5——模版库、工具类及控件
264 0
QT5——模版库、工具类及控件(下)
|
存储 算法 安全
QT5——模版库、工具类及控件(上)
QT5——模版库、工具类及控件
243 0
QT5——模版库、工具类及控件(上)
|
IDE 开发工具 C语言
OpenGL学习笔记(七):创建第一个Qt5.9.3 OpenGL工程模版(与平台无关)
OpenGL学习笔记(七):创建第一个Qt5.9.3 OpenGL工程模版(与平台无关)
OpenGL学习笔记(七):创建第一个Qt5.9.3 OpenGL工程模版(与平台无关)
Qt QWidget 软件开发模版
Qt QWidget 软件开发模版
120 0
Qt QWidget 软件开发模版
|
1月前
|
数据安全/隐私保护 C++ 计算机视觉
Qt(C++)开发一款图片防盗用水印制作小工具
文本水印是一种常用的防盗用手段,可以将文本信息嵌入到图片、视频等文件中,用于识别和证明文件的版权归属。在数字化和网络化的时代,大量的原创作品容易被不法分子盗用或侵犯版权,因此加入文本水印成为了保护原创作品和维护知识产权的必要手段。 通常情况下,文本水印可以包含版权声明、制作者姓名、日期、网址等信息,以帮助识别文件的来源和版权归属。同时,为了增强防盗用效果,文本水印通常会采用字体、颜色、角度等多种组合方式,使得水印难以被删除或篡改,有效地降低了盗用意愿和风险。 开发人员可以使用图像处理技术和编程语言实现文本水印的功能,例如使用Qt的QPainter类进行文本绘制操作,将文本信息嵌入到图片中,
99 1
Qt(C++)开发一款图片防盗用水印制作小工具
|
5天前
|
监控 C++ 容器
【qt】MDI多文档界面开发
【qt】MDI多文档界面开发
15 0
Qt开发网络嗅探器02
Qt开发网络嗅探器02
|
1天前
|
存储 运维 监控
Qt开发网络嗅探器01
Qt开发网络嗅探器01
|
1天前
|
网络协议 容器
Qt开发网络嗅探器03
Qt开发网络嗅探器03
|
5天前
【qt】多窗口开发
【qt】多窗口开发
8 0