当前位置:网站首页>Qt-Char实现动态波形显示
Qt-Char实现动态波形显示
2022-06-09 10:05:00 【温逗死】
通过定时器中断,实现简单的曲线动态显示
charttest.h
#ifndef CHARTTEST_H
#define CHARTTEST_H
#include <QtWidgets/QWidget>
#include "ui_charttest.h"
#include <QHBoxLayout>
#include "myChart.h"
#define PI 3.14159
using namespace std;
class chartTest : public QWidget
{
Q_OBJECT
public:
chartTest(QWidget *parent = 0);
~chartTest();
int MaxSample = 100;
QValueAxis* vaX, *vaY1;
QSplineSeries* spY1;
private slots:
void timer1Slot();
private:
Ui::chartTestClass ui;
myChart* mChart;
QVector<QPointF> vecKv;
void iniChart();
};
#endif // CHARTTEST_H
charttest.cpp
#include "charttest.h"
chartTest::chartTest(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
mChart = new myChart();
mChart->setFixedSize(800, 800);
iniChart();
QTimer* timer1 = new QTimer(this);
timer1->setInterval(10);
connect(timer1, SIGNAL(timeout()), this, SLOT(timer1Slot()));
timer1->start();
}
chartTest::~chartTest()
{
}
void chartTest::iniChart()
{
mChart->setEnabled(true);
mChart->chart()->setTitle("Kv-Vacuum");
mChart->chart()->legend()->hide();
mChart->chart()->setTheme(QtCharts::QChart::ChartTheme::ChartThemeDark);
vaX = new QValueAxis();
vaY1 = new QValueAxis();
spY1 = new QSplineSeries();
vaX->setRange(0, MaxSample);
vaX->setTickCount(7);
vaX->setLabelsColor(QColor(0, 255, 0));
vaX->setTitleText("Sample-Points");
vaY1->setRange(0, 200);
vaY1->setTickCount(6);
vaY1->setLabelsColor(QColor(255,0, 0));
vaY1->setTitleText("Voltage-Kv");
mChart->chart()->addAxis(vaX, Qt::AlignBottom);
mChart->chart()->addAxis(vaY1, Qt::AlignLeft);
mChart->chart()->addSeries(spY1);
spY1->attachAxis(vaX);
spY1->attachAxis(vaY1);
spY1->setColor(QColor(255, 0, 0));
spY1->setUseOpenGL();
QHBoxLayout* hlay = new QHBoxLayout();
hlay->addWidget(mChart);
this->setLayout(hlay);
}
void chartTest::timer1Slot()
{
static int cnt = 0;
if (cnt <= MaxSample)
{
float tmp = 85.0 + 85 * sin(cnt * 4 * PI / MaxSample);
vecKv.push_back(QPointF(cnt, tmp));
}
else
{
for (int i = 1; i < MaxSample; ++i)
{
vecKv[i - 1] = QPointF(vecKv[i - 1].x(), vecKv[i].y());
}
float tmp = 85.0 + 85 * sin(cnt * 4 * PI / MaxSample);
vecKv[MaxSample-1] = QPointF(vecKv[MaxSample-1].x(), tmp);
if (cnt >= 10 * MaxSample)
{
cnt = 0;
vecKv.clear();
}
}
cnt++;
spY1->replace(vecKv);
}
边栏推荐
- Application of ebpf in cloud native environment
- 关于在线帮助中心你需要思考以下几个问题
- dict中的部分指令与set中的差和交集与增减元素
- 叁拾玖- SQL对数据内容 分段/分组 汇总
- ISCC2022 擂台misc
- 什么样的数字藏品平台才是好平台?
- 开发一个软件应用程序需要多少钱?
- Kubernetes第七篇:Pod進階、Controller進階、Resource和Dashboard
- [PHP] brief description and relevant examples of the special class trail for code reuse
- 三拾壹- NodeJS簡單代理池(合) 之 MongoDB 鏈接數爆炸了
猜你喜欢

三拾壹- NodeJS簡單代理池(合) 之 MongoDB 鏈接數爆炸了
![[model deployment and business implementation] model transformation of AI framework deployment scheme](/img/ea/8ca6bc6ae16ba1f90f6a5a38be184d.jpg)
[model deployment and business implementation] model transformation of AI framework deployment scheme

“当你不再是程序员,很多事会脱离掌控”—— 对话全球最大独立开源公司SUSE CTO...

Le nombre de liens mongodb pour le pool d'agents simples de nodejs a explosé

WPF implements ring chart with details
![[genius_platform software platform development] lecture 37: network card hybrid mode and raw socket](/img/bf/880fbf4122b66723b6e17c6d9d97c9.jpg)
[genius_platform software platform development] lecture 37: network card hybrid mode and raw socket

叁拾柒- JS 在 Canvas 上尝试分形图形 (一) 画了一个普通箱子图
![N-grams language model -- [torch learning notes]](/img/94/c5c4ac70590158b3c21d18c3b86a6f.png)
N-grams language model -- [torch learning notes]
![[image enhancement] image enhancement based on sparse representation and regularization with matlab code](/img/0c/3755a74a68ae7ac8232774881d618a.png)
[image enhancement] image enhancement based on sparse representation and regularization with matlab code

1340. jumping game v-dynamic planning plus DFS
随机推荐
Key configuration points of video fusion cloud service easycvr platform deployed in ECS
多线程之生产者和消费者模型
数学公式显示
Lua调用原理展示(Lua堆栈)
Unemployment wave? Yuancosmos opens up new employment opportunities
Sword finger offer 18 Delete the node of the linked list
The more you look at the screen, the better it looks
WPF implements ring chart with details
Tensorflow new document publishing: add CLP, dtensor The most advanced model is ready!
flutter 按字母 排序 通讯录并点击滑动
视频融合云服务EasyCVR平台部署在云服务器中的配置关键点
Interview question 04.02 Minimum height tree - depth first traversal, plus tree divide and conquer
Is it safe to open an account at flush
Today in history: PHP is publicly released; IPhone 4 comes out; The birth of the father of the World Wide Web
投稿开奖丨轻量应用服务器征文活动(4月)奖励公布
15 must know MySQL index failure scenarios, stop stepping on the pit!
Security monitoring video easycvr video access interface adds the close button of a single video
InfoQ geek media's 15th anniversary solicitation 𞓜 migration of Eureka to Nacos: dual registration and dual subscription model
[fruit recognition] fruit recognition based on morphology, including Matlab source code
error NU1202: Package Volo.Abp.Cli 5.2.1 is not compatible with netcoreapp3.1