凡客诚品官方网站查询,dedecms 网站重复文章,唐河网站制作,十堰吧程序示例精选 QtC动力监控动画仿真SCADA上位机 如需安装运行环境或远程调试#xff0c;见文章底部个人QQ名片#xff0c;由专业技术人员远程协助#xff01; 前言
这篇博客针对QtC动力监控动画仿真SCADA上位机编写代码#xff0c;代码整洁#xff0c;规则… 程序示例精选 QtC动力监控动画仿真SCADA上位机 如需安装运行环境或远程调试见文章底部个人QQ名片由专业技术人员远程协助 前言
这篇博客针对QtC动力监控动画仿真SCADA上位机编写代码代码整洁规则易读。 学习与应用推荐首选。 文章目录
一、所需工具软件
二、使用步骤 1. 引入库 2. 代码实现 3. 运行结果
三、在线协助 一、所需工具软件
1. VS, Qt
2. C 二、使用步骤
1.引入库
#include MainWindow.h#includeiostream
#include QThread#include thread
#include chrono
#include QObject
#include QThread
#include QDebug
#include QFile
#include QTimer
#include QMutex
#include QWaitCondition
#includeopencv2/opencv.hpp
#include QDebug
#include QBitmap
#include QPainter#includeQImage
#includeQPixmap
#includeQTransform
#includeQPropertyAnimation
#includeQGraphicsPixmapItem
#includeQGraphicsScene
#include QtConcurrent/QtConcurrent
2. 代码实现
代码如下:
void MainWindow::lightStrip1()
{
# if 1int imageCount 11;int imageSpacing 5; // 图片间距-85qDebug() 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远程安装运行环境代码调试 2Qt, C, Python入门指导 3界面美化 4软件制作 当前文章连接PythonQt桌面端与网页端人工客服沟通工具_alicema1111的博客-CSDN博客
博主推荐文章python人脸识别统计人数qt窗体-CSDN博客
博主推荐文章Python Yolov5火焰烟雾识别源码分享-CSDN博客 Python OpenCV识别行人入口进出人数统计_python识别人数-CSDN博客
个人博客主页alicema1111的博客_CSDN博客-Python,C,网页领域博主
博主所有文章点这里alicema1111的博客_CSDN博客-Python,C,网页领域博主