QCustomplot(零)QCustomPlot官方Demo使用

一、在哪儿下载?

进入官方网站:https://www.qcustomplot.com/index.php/download,根据需要选择需要的文件:

  • 完整版。QCustomPlot.tar.gz 源代码+例子+帮助文档;
  • 共享库。QCustomPlot-sharedlib.tar.gz 库编译和使用;
  • 源代码。QCustomPlot-source.tar.gz 源代码

假如你是第一次使用,建议选择完整版。下面以完整版为例说明如何使用。

二、完整版内容

解压后找到文件夹qcustomplot,内容如下:

└── qcustomplot
    ├── changelog.txt
    ├── documentation
    │   ├── html
    │   └── qcustomplot.qch
    ├── examples
    │   ├── axis-tags
    │   ├── interactions
    │   ├── plots
    │   ├── scrollbar-axis-range-control
    │   └── text-document-integration
    ├── GPL.txt
    ├── qcustomplot.cpp
    └── qcustomplot.h
  • 更新日志 changelog.txt
  • 帮助文档 documentation,安装之后可以直接查阅用法
  • 例子工程 examples
  • 版权声明 GPL.txt
  • 源文件和头文件 qcustomplot.cpp qcustomplot.h

三、有什么Demo? 如何在自己项目上使用它?

examples中有五个工程,分别是:

  • axis-tags 轴标签
  • interactions 交互
  • plots 绘制
  • scrollbar-axis-range-control 滚动条
  • text-document-integration 输出图像到文档

以plots为例,说明demo如何利用QCustomPlot类运行和编写。找到.pro文件,用creator打开这个pro文件:
1
pro文件内容如下:

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport

greaterThan(QT_MAJOR_VERSION, 4): CONFIG += c++11
lessThan(QT_MAJOR_VERSION, 5): QMAKE_CXXFLAGS += -std=c++11

TARGET = plot-examples
TEMPLATE = app

SOURCES += main.cpp\
           mainwindow.cpp \
         ../../qcustomplot.cpp

HEADERS  += mainwindow.h \
         ../../qcustomplot.h

FORMS    += mainwindow.ui

为了使用QCustomPlot这个类,项目上需要做以下两点:

  • 添加了头文件和源文件的相对路径,在引用处#include "../../qcustomplot.h"即可。对于QT5你可能需要额外加上QT += widgets printsupport
  • ui界面上处理,将QWidget提升为QCustomPlot,自己工程可能需要在原来的UI上添加一个QWidget,然后右键弹出的菜单选择promote to,填写好头文件和类名字,点击提升完成QCustomPlot在desinger上的表现(就好像你拖了一个QPushButtom空间一样)。
    在这里插入图片描述
    PS:假如一个类基类是QWidget,那么你可以在UI界面上直观的操作它,方法是提升。

三、Demo内容

  ui->setupUi(this);
  setGeometry(400, 250, 542, 390);
  
  setupDemo(0);
  //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()));

通过setupDemo函数传入的序号,即可看到相应的Demo及其实现方法。默认是运行QuadraticDemo,运行结果如下:
2
将序号0改成19,运行结果如下:
3
仔细找找你要的绘图效果,参照源代码即可完成工程上的大多数应用。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值