qtvs2017+qt使用qcustomplot绘图(代码片段)

ZHONGCAI0901 ZHONGCAI0901     2022-12-10     718

关键词:

文章目录

1. 前言

QCustomPlot 是一个超强超小巧的qt绘图类,非常漂亮,非常易用,只需要加入一个qcustomplot.hqcustomplot.cpp文件即可使用。

官方网址:https://www.qcustomplot.com/

下面是运行的效果如下:

2. 下载QCustomPlot的源码

源码下载地址:https://www.qcustomplot.com/index.php/download

3. 将QCustomPlot添加到QT项目

qcustomplot.hqcustomplot.cpp2个文件添加到QT项目,如下:

在项目属性Qt Project Settings中,添加QT模块printsupport,如下:

在ui布局文件添加一个Widget,然后选择提升为...,如下:

在弹框提升的类名称中,填写QCustomPlot,然后选择添加

编译工程,运行效果如下:

4. 移植QCustomPlot Demo中的plots

解压QCustomPlot.tar.gz后,将qcustomplot\\examples\\plots移植到当前工程。通过修改setupDemo()来选择测试的demo,部分源码如下:

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)

    ui.setupUi(this);
	setGeometry(400, 250, 542, 390);

	setupDemo(12);
	//setupPlayground(ui.customPlot);
	// 0:  setupQuadraticDemo(ui.customPlot);
	// 1:  setupSimpleDemo(ui.customPlot);
	// 2:  setupSincScatterDemo(ui.customPlot);
	// 3:  setupScatterStyleDemo(ui.customPlot);
	// 4:  setupScatterPixmapDemo(ui.customPlot);
	// 5:  setupLineStyleDemo(ui.customPlot);
	// 6:  setupDateDemo(ui.customPlot);
	// 7:  setupTextureBrushDemo(ui.customPlot);
	// 8:  setupMultiAxisDemo(ui.customPlot);
	// 9:  setupLogarithmicDemo(ui.customPlot);
	// 10: setupRealtimeDataDemo(ui.customPlot);
	// 11: setupParametricCurveDemo(ui.customPlot);
	// 12: setupBarChartDemo(ui.customPlot);
	// 13: setupStatisticalDemo(ui.customPlot);
	// 14: setupSimpleItemDemo(ui.customPlot);
	// 15: setupItemDemo(ui.customPlot);
	// 16: setupStyledDemo(ui.customPlot);
	// 17: setupAdvancedAxesDemo(ui.customPlot);
	// 18: setupColorMapDemo(ui.customPlot);
	// 19: setupFinancialDemo(ui.customPlot);
	// 20: setupPolarPlotDemo(ui.customPlot);

	// for making screenshots of the current demo or all demos (for website screenshots):
	//QTimer::singleShot(1500, this, SLOT(allScreenShots()));
	//QTimer::singleShot(4000, this, SLOT(screenShot()));


void MainWindow::setupDemo(int demoIndex)

	switch (demoIndex)
	
	case 0:  setupQuadraticDemo(ui.customPlot); break;
	case 1:  setupSimpleDemo(ui.customPlot); break;
	case 2:  setupSincScatterDemo(ui.customPlot); break;
	case 3:  setupScatterStyleDemo(ui.customPlot); break;
	case 4:  setupScatterPixmapDemo(ui.customPlot); break;
	case 5:  setupLineStyleDemo(ui.customPlot); break;
	case 6:  setupDateDemo(ui.customPlot); break;
	case 7:  setupTextureBrushDemo(ui.customPlot); break;
	case 8:  setupMultiAxisDemo(ui.customPlot); break;
	case 9:  setupLogarithmicDemo(ui.customPlot); break;
	case 10: setupRealtimeDataDemo(ui.customPlot); break;
	case 11: setupParametricCurveDemo(ui.customPlot); break;
	case 12: setupBarChartDemo(ui.customPlot); break;
	case 13: setupStatisticalDemo(ui.customPlot); break;
	case 14: setupSimpleItemDemo(ui.customPlot); break;
	case 15: setupItemDemo(ui.customPlot); break;
	case 16: setupStyledDemo(ui.customPlot); break;
	case 17: setupAdvancedAxesDemo(ui.customPlot); break;
	case 18: setupColorMapDemo(ui.customPlot); break;
	case 19: setupFinancialDemo(ui.customPlot); break;
	case 20: setupPolarPlotDemo(ui.customPlot); break;
	
	setWindowTitle("QCustomPlot: " + demoName);
	statusBar()->clearMessage();
	currentDemoIndex = demoIndex;
	ui.customPlot->replot();

运行效果如下:

5. 移植过程出现的问题

问题1:编译时的错误log

1>ui_qtwidgetsapplication1.h(15): fatal error C1083: 无法打开包括文件: “qcustomplot.h”: No such file or directory (编译源文件 main.cpp)
1>ui_qtwidgetsapplication1.h(15): fatal error C1083: 无法打开包括文件: “qcustomplot.h”: No such file or directory (编译源文件 QtWidgetsApplication1.cpp)

解决办法:

因为和工程在同一个目录,设置头文件路径如下:打开项目属性 -> C/C++ -> 常规 -> 附加包含目录 -> $(ProjectDir)

问题2:编译时的错误log

1>qcustomplot.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall QPrinter::QPrinter(enum QPrinter::PrinterMode)" (??0QPrinter@@QAE@W4PrinterMode@0@@Z),该符号在函数 "public: bool __thiscall QCustomPlot::savePdf(class QString const &,int,int,enum QCP::ExportPen,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QAE_NABVQString@@HHW4ExportPen@QCP@@00@Z) 中被引用
1>qcustomplot.obj : error LNK2019: 无法解析的外部符号 "public: virtual __thiscall QPrinter::~QPrinter(void)" (??1QPrinter@@UAE@XZ),该符号在函数 "public: bool __thiscall QCustomPlot::savePdf(class QString const &,int,int,enum QCP::ExportPen,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QAE_NABVQString@@HHW4ExportPen@QCP@@00@Z) 中被引用
1>qcustomplot.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall QPrinter::setOutputFormat(enum QPrinter::OutputFormat)" (?setOutputFormat@QPrinter@@QAEXW4OutputFormat@1@@Z),该符号在函数 "public: bool __thiscall QCustomPlot::savePdf(class QString const &,int,int,enum QCP::ExportPen,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QAE_NABVQString@@HHW4ExportPen@QCP@@00@Z) 中被引用
1>qcustomplot.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall QPrinter::setOutputFileName(class QString const &)" (?setOutputFileName@QPrinter@@QAEXABVQString@@@Z),该符号在函数 "public: bool __thiscall QCustomPlot::savePdf(class QString const &,int,int,enum QCP::ExportPen,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QAE_NABVQString@@HHW4ExportPen@QCP@@00@Z) 中被引用
1>qcustomplot.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall QPrinter::setColorMode(enum QPrinter::ColorMode)" (?setColorMode@QPrinter@@QAEXW4ColorMode@1@@Z),该符号在函数 "public: bool __thiscall QCustomPlot::savePdf(class QString const &,int,int,enum QCP::ExportPen,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QAE_NABVQString@@HHW4ExportPen@QCP@@00@Z) 中被引用
1>qcustomplot.obj : error LNK2019: 无法解析的外部符号 "public: class QPrintEngine * __thiscall QPrinter::printEngine(void)const " (?printEngine@QPrinter@@QBEPAVQPrintEngine@@XZ),该符号在函数 "public: bool __thiscall QCustomPlot::savePdf(class QString const &,int,int,enum QCP::ExportPen,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QAE_NABVQString@@HHW4ExportPen@QCP@@00@Z) 中被引用

解决办法:
打开项目属性 -> Qt Project Settings -> Qt Modules -> 增加printsupport

5. 测试demo完整工程

测试时的完成工程代码下载路径如下:
https://download.csdn.net/download/ZHONGCAI0901/20964210?spm=1001.2014.3001.5501

qt使用qcustomplot开发

一、入门1、下载源文件http://www.qcustomplot.com/;2、把.cpp和.h放在工程目录下,并将cpp和h加入工程;3、在.pro中:QT+=printsupport;4、在ui中添加一个Widget,右键提升为,输入:QCustomPlot,改变对象名称为customPlot;5、加入代码:voidMain... 查看详情

使用qt绘图控件qcustomplot绘制波形图(代码片段)

...受到的数据通过曲线显示出来,其实这是用一个叫做QCustomPlot的控件,这个控件不是QT自带的,需要自己下载加入,今天介绍一下这个控件的使用方法,并附源码。QCustomPlot简介QCustomPlot是开源的Qt的第三方绘图... 查看详情

使用qt绘图控件qcustomplot绘制波形图(代码片段)

...受到的数据通过曲线显示出来,其实这是用一个叫做QCustomPlot的控件,这个控件不是QT自带的,需要自己下载加入,今天介绍一下这个控件的使用方法,并附源码。QCustomPlot简介QCustomPlot是开源的Qt的第三方绘图... 查看详情

qt绘图插件qcustomplot下载安装配置使用

一、配置QCustomPlot官方下载地址:http://www.qcustomplot.com/index.php/download650)this.width=650;"src="http://img.blog.csdn.net/20151010144651708?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fonts 查看详情

Qt5 QCustomPlot。实时大图

】Qt5QCustomPlot。实时大图【英文标题】:Qt5QCustomPlot.Largegraphinrealtime【发布时间】:2015-12-0913:00:07【问题描述】:我目前正在开发一个实时绘制来自ADC的数据的应用程序。在某些情况下,我必须绘制大约150k点,这需要一些时间。... 查看详情

qtvs2017《五子棋》人机对战项目(代码片段)

一年了。一年前,自己学习qt语言时,顺便写了一个五子棋的小项目,个人感觉,这个五子棋项目还算挺大型的,整个项目代码量加起来可能有1w行,现在分享出来给有需要的朋友,参考借鉴。项目包括... 查看详情

qt使用qcustomplot绘制柱状图

...,  ui(newUi::ClgBar)  ui->setupUi(this);  QCustomPlot* m_rectPlot=newQCustomPlot;  ui->verticalLayout->addWidget(m_rectPlot);  m_rectPlot->xAxis->setLabel("参数");  m_rectPlot->yAxis->setLabel("个... 查看详情

MSVS2012 中的 QCustomPlot

】MSVS2012中的QCustomPlot【英文标题】:QCustomPlotinMSVS2012【发布时间】:2015-04-0811:12:26【问题描述】:我成功地在VisualStudio2012中构建了一个无需插件即可运行QT的程序。我包含了QT包含文件夹并手动将库添加到资源中。它编译并运行... 查看详情

如何在qtvs中利用qt进行界面设计

参考技术A安装Qt,VS和 Qt5VisualStudioAdd-in.配置好环境变量,如qmake_path和QTDIR.打开VS查看是否有"QT"工具栏.点击文件->新建->项目,在左边模板中选择QtProject,然后在右边选择QtApplication输入名称和解决方案名称,位置不能有... 查看详情

qt使用qcustomplot绘制曲线例子

...(newUi::MainWindow)  ui->setupUi(this);  m_pPlot=newQCustomPlot;  m_pPlot->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom|QCP::iMultiSelect|QCP::iSelectOther|QCP::iSelectItems);  m_pPlot->axisRect()->setupFullAxesBox();  m_pPlot->xAxi... 查看详情

qt绘图技术qcustomplot-超强超小巧的qt绘图控件

QCustomPlot-超强超小巧的qt绘图控件  2016-10-2216:03:25|  分类: QT|官方网站:http://www.qcustomplot.com/1.0下载地址:http://download.csdn.net/detail/czyt1988/5986701  下载LOFTER我的照片书 &n 查看详情

qtvs2022使用qcefview控件与html通信(代码片段)

此前,主管让我调研cef3的使用,但是cef3比较复杂,太难理解了;偶然间,在网上看到有QT第三方库QCefView,这个库封装了cef3,使得可以很简单的在桌面应用加载显示html,并与其进行通信;经过... 查看详情

qt之qcustomplot(图形库)

简述QCustomPlot是一个基于QtC++的图形库,用于绘制和数据可视化-制作漂亮的2D图-曲线图、趋势图、坐标图、柱状图等,并为实时可视化应用程序提供高性能服务。它没有进一步的依赖关系,并有着良好的文档记... 查看详情

qcustomplot基本使用(代码片段)

文章目录简述下载使用简述QCustomPlot是一个基于QtC++的图形库,用于绘制和数据可视化-制作漂亮的2D图-曲线图、趋势图、坐标图、柱状图等,并为实时可视化应用程序提供高性能服务。它没有进一步的依赖关系,... 查看详情

如何有效地使用 QCustomPlot 绘制大型时间序列?

】如何有效地使用QCustomPlot绘制大型时间序列?【英文标题】:HowtoplotlargetimeserieswithQCustomPlotefficiently?【发布时间】:2014-12-1107:44:52【问题描述】:我目前正在使用QCustomPlot在Qt中绘制数字信号,但似乎当样本数大于10000000时,操... 查看详情

qt_qcustomplot学习(代码片段)

QCustomPlot学习QCustomPlot默认提供了6个层,如下代码所示,分别是:背景层、网格层、主层、坐标轴层、图例层和矩形选择区域层。1.在一张视图中表现两个线#include"widget.h"#include"ui_widget.h"Widget::Widget(QWidget*pa... 查看详情

qt_qcustomplot学习(代码片段)

QCustomPlot学习QCustomPlot默认提供了6个层,如下代码所示,分别是:背景层、网格层、主层、坐标轴层、图例层和矩形选择区域层。1.在一张视图中表现两个线#include"widget.h"#include"ui_widget.h"Widget::Widget(QWidget*pa... 查看详情

qtvs2022使用qcefview控件与html通信(代码片段)

此前,主管让我调研cef3的使用,但是cef3比较复杂,太难理解了;偶然间,在网上看到有QT第三方库QCefView,这个库封装了cef3,使得可以很简单的在桌面应用加载显示html,并与其进行通信;经过... 查看详情