Qt+C++动力监控动画仿真SCADA上位机

 程序示例精选

Qt+C++动力监控动画仿真SCADA上位机

如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!

前言

这篇博客针对<<Qt+C++动力监控动画仿真SCADA上位机>>编写代码,代码整洁,规则,易读。 学习与应用推荐首选。


文章目录

一、所需工具软件

二、使用步骤

        1. 引入库

        2. 代码实现

        3. 运行结果

三、在线协助

一、所需工具软件

1. VS, Qt

2. C++

二、使用步骤

1.引入库

#include "MainWindow.h"

#include<iostream>
#include <QThread>

#include <thread>
#include <chrono>
#include <QObject>
#include <QThread>
#include <QDebug>
#include <QFile>
#include <QTimer>
#include <QMutex>
#include <QWaitCondition>
#include<opencv2/opencv.hpp>
#include <QDebug>
#include <QBitmap>
#include <QPainter>

#include<QImage>
#include<QPixmap>
#include<QTransform>
#include<QPropertyAnimation>
#include<QGraphicsPixmapItem>
#include<QGraphicsScene>
#include <QtConcurrent/QtConcurrent>

2. 代码实现

代码如下:

void MainWindow::lightStrip1()
{
# if 1

    int imageCount = 11;
    int imageSpacing = 5; // 图片间距,-85

    qDebug() << "lightStrip2";
    QLabel* labelName = ui.label_4;

    int labelWidth = labelName->width();
    int labelHeight = labelName->height();
    qDebug() << "labelWidth: " << labelWidth;
    qDebug() << "labelHeight: " << labelHeight;
    qDebug() << "";

    labelName->clear();

    // 创建画布,与label_3一样大小
    QPixmap canvas(labelName->size());
    canvas.fill(Qt::transparent);

    // 创建画家并将画布设置为绘制目标
    QPainter painter(&canvas);

    // 计算每个加载的图片y坐标
    int y = yPos1;

    // 计算每个图片的总高度(包括间距)
    //int totalHeight = imageCount * (labelName->height() + imageSpacing) - imageSpacing - 80;
   //  int totalHeight = 100;
    int totalHeight = labelName->height();
    qDebug() << "totalHeight: " << totalHeight;

    // 同时绘制多个图片
    for (int i = 0; i < imageCount; i++) {
        // 加载当前图片
        QString imagePath = QString("./imgLightStrip/%1.png").arg(i + 1);
        QPixmap image(imagePath);

        // 定义新的尺寸
        int newWidth = 30;  // 替换为所需的宽度
        int newHeight = 100;  // 替换为所需的高度
        // 调整图片尺寸
        QPixmap resizedImage = image.scaled(newWidth, newHeight);


        int imageWidth = resizedImage.width();
        int imageHeight = resizedImage.height();
        qDebug() << "imageWidth: " << imageWidth;
        qDebug() << "imageHeight: " << imageHeight;
        qDebug() << "";

        int imageWidthT = labelName->width() * 0.3; //用label宽度的0.3比例作为图片宽度
        int imageHeightT = imageHeight * (labelName->width() * 0.3) / imageWidth;
        qDebug() << "imageWidthT: " << imageWidthT;
        qDebug() << "imageHeightT: " << imageHeightT;
        qDebug() << "";



        // 调整图片尺寸以适应label_3的宽度
        QPixmap scaledImage = resizedImage.scaledToWidth(labelName->width() * 0.3);

        // 计算水平居中的x坐标
        int x = (labelName->width() - scaledImage.width()) / 2;

        // 更新y坐标,实现图片向下流动的效果
        //y += totalHeight + 5; // 5是每个图片之间的间隔
        //int y = yPos + i * (labelName->height() + imageSpacing);
        int y = yPos1 + i * (imageHeightT + imageSpacing);
        if (y >= labelName->height()) { // 图片完全超出上方可视区域时,重新调整y坐标
            y -= totalHeight;
        }

        // 将图片绘制到画布上
        painter.drawPixmap(x, y, scaledImage);

        // 如果图片完全超出下方可视区域时,重新调整y坐标
        //if (y >= labelHeight + imageHeightT + 5) {
        //    y = yPos;
        //}
    }

#endif
}
class WorkerThread3 : public QThread {
	Q_OBJECT
public:
	void run() override {
		QTimer timer3;
		connect(&timer3, &QTimer::timeout, this, &WorkerThread3::lightStrip3);
		timer3.start(200); // 设置定时器间隔,单位为毫秒
		exec();
	}

	~WorkerThread3() {
		quit();  // 请求线程退出
		wait();  // 等待线程完成
	}

signals:
	void lightStrip3();
};

3. 运行结果

动画演示

三、在线协助:

如需安装运行环境或远程调试,见文章底部个人 QQ 名片,由专业技术人员远程协助!
1)远程安装运行环境,代码调试
2)Qt, C++, Python入门指导
3)界面美化
4)软件制作

当前文章连接:Python+Qt桌面端与网页端人工客服沟通工具_alicema1111的博客-CSDN博客

博主推荐文章:python人脸识别统计人数qt窗体-CSDN博客

博主推荐文章:Python Yolov5火焰烟雾识别源码分享-CSDN博客

                         Python OpenCV识别行人入口进出人数统计_python识别人数-CSDN博客

个人博客主页:alicema1111的博客_CSDN博客-Python,C++,网页领域博主

博主所有文章点这里alicema1111的博客_CSDN博客-Python,C++,网页领域博主

猜你喜欢

转载自blog.csdn.net/alicema1111/article/details/132452517