跳转至

概述

Qt 生态里能画图的库不多,主流的为QCustomPlotQwtQt ChartsKDChart,Qt6.8之后把原来的 Qt Charts(2D) 与 Qt DataVisualization(3D) 合并为统一的Qt Graphs模块(注意不是Qt Graphics),底层全部基于 Qt Quick Scene Graph(QSG)+ Qt Quick 3D,彻底放弃了老旧的 Graphics-View/QPainter 管线,不过Qt Graphs 须通过 QQuickWidget 或 QQuickWindow 嵌入,必须带 QML runtime,C++支持不足,论坛吐槽不少,虽然Qt Graphs 是 Qt 官方“大一统”的未来,但这个未来可能3年内不会到来,且不支持win7等老系统,对嵌入式也不友好,因此,QCustomPlotQwtQt ChartsKDChart还会是最近几年绘图控件的选项。

这几个控件QCustomPlot最简单、美观,推广度最高,只要引入qcustomplot.h头文件,qcustomplot.cpp源文件,就可以直接使用(官方文档),也支持Qt6,然而QCustomPlot最大的问题是其开源协议为GPL,有传染性,如果你使用了QCustomPlot,意味着你的软件也要成为GPL,这对商业非常不友好。

Qwt是老牌的绘图控件(官方文档),有着不错的性能,但部署难,让很多人望而怯步。它的协议为LGPL,商业相对友好。

Qt Charts是Qt官方的绘图控件(官方文档),效率不高(可以说很低),不适合做科学计算,同时,Qt Charts 没有 LGPL 选项,开源版是GPLv3,只要你在项目中使用了Qt Charts,就必须 把整个项目以 GPLv3 协议开源。

KDChart是KDAB的绘图控件(官方文档),KDChart3.0起是MIT协议,对商业非常友好,但渲染效果一般,一股excel2003的风格,但KDChart有甘特图,这是上面3款都没有的。

因此,如果你的项目需要商业用途,那么你只有QwtKDChart3.0两种选择,但Qwt作者停止更新,我个人更喜欢Qwt,因为Qwt的架构更符合软件工程原则,其大规模渲染性能更优,像QCustomPlot的优势是交互功能开箱即用,例如鼠标缩放,坐标轴缩放,而Qwt需要较多的代码来实现,但Qwt有着更精细的控制能力,因此在我的项目需要绘图的时候,我会选择Qwt,并根据我的需求添加一些自己需要的功能,改进、优化它,因此,就有了此项目。

Qwt 7.0

我在Qwt最后版本上进行了维护,后续我将我需要的功能添加进去,同时逐步修改、优化一些已有的功能,例如它默认的老旧样式

项目地址为:

Github:https://github.com/czyt1988/QWT

Gitee:https://gitee.com/czyt1988/QWT

下面是我的目标以及目前我已经完成的一些工作:

  • CMake支持
  • 支持Qt6
  • C++11优化
  • 合并为单一文件,简化引入
  • 优化超大规模数据的渲染
  • 提供一些集成的交互方法,让使用更简单(提供了坐标轴交互、绘图窗口移动缩放等功能)
  • 美化控件
  • 提供Figure实现绘图的布局
  • 增加寄生轴的支持,实现n个坐标轴

总之,我将继续维护Qwt,让其成为一个协议友好,性能优越,方便使用的Qt绘图库

Qwt7.0的新特性

Cmake支持

Qwt7.0已经支持CMake,并且未来将考虑抛弃QMake

安装Qwt后,你的项目只需如下即可引入Qwt,免去以往繁琐的配置和预定义宏:

1
target_link_libraries(${YOU_APP_TARGET} PUBLIC qwt::qwt)

单一头文件和源文件

参考QCustomPlot,我把原Qwt整个工程合并为QwtPlot.hQwtPlot.cpp,只要把这两个文件引入项目即可使用

美化了风格

原有的Qwt样式使用的是很老旧的浮雕风,和现代审美不符,为此我针对性的优化,主要去除了默认的凹陷风格,坐标轴紧贴绘图不进行分离,总体视觉更符合现代风格

具体可见屏幕快照

增加了Figure绘图容器

类似Python的matplotlib,Qwt提供了Figure绘图容器,可以很方便的进行多个绘图布局

通过新增的QwtFigure类,可以很方便的进行多个绘图布局,支持网格布局(类似matplotlib的subplot)

支持多坐标轴

增加了类似matplotlib的寄生轴功能,支持任意多个坐标轴显示

parasite plot

增加了坐标轴交互

增加坐标轴交互功能,支持在坐标轴上使用鼠标拖动、滚轮缩放等功能

拖动:
qwt-scale-builtin-action-pan

缩放:
qwt-scale-builtin-action-zoom


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
Qwt Widget Library 
Copyright (C) 1997   Josef Wilgen
Copyright (C) 2002   Uwe Rathmann

Qwt is published under the Qwt License, Version 1.0.
You should have received a copy of this licence in the file
COPYING.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

绘图展示

基本图表

  • Figure Widget
    examples/figure

  • Simple Plot
    examples/simpleplot

  • Bar Chart - Grouped
    examples/barchart

  • Bar Chart - Stacked
    examples/barchart

  • Scatter Plot
    examples/scatterplot

  • Curve Demo
    examples/curvedemo

实时可视化

  • CPU Monitor
    examples/cpuplot

  • Real-Time Plot
    examples/realtime

  • Oscilloscope
    examples/oscilloscope

高级图表

  • Polar Demo
    examples/polardemo

  • Spectrogram
    examples/spectrogram

  • Contour Spectrogram
    examples/spectrogram

  • Vector Field
    playground/vectorfield

  • Stock Chart
    examples/stockchart

  • Bode Plot
    examples/bode

  • Tube Display
    examples/friedberg

  • plot matrix
    playground/plotmatrix

  • Scale Engine
    playground/scaleengine

  • Rescaler
    playground/rescaler

  • Graphics Scale
    playground/graphicscale

  • Spline Editor
    examples/splineeditor

  • System Info
    examples/sysinfo

  • Distro Watch
    examples/distrowatch

  • Raster View 1
    examples/rasterview

  • Raster View 2
    examples/rasterview

  • SVG Map
    playground/svgmap

  • parasite plot
    examples/parasitePlot

动态演示

  • Animated Demo
    examples/animated

  • Curve Tracker
    playground/curvetracker

  • Refresh Test
    examples/refreshtest

样式与符号

  • Legends Demo
    examples/legends

  • Symbols Demo
    playground/symbols

  • Shape Rendering
    playground/shapes

控件窗口

  • Dial Controls
    examples/controls

  • Knob Controls
    examples/controls

  • Slider Controls
    examples/controls

  • Wheel & Thermo
    examples/controls

  • Radio Buttons
    examples/radio

  • Time Scale Demo
    playground/timescale

仪表盘

  • Compass Dial
    examples/dials

  • Cockpit Dials
    examples/dials