Qtchart教程
由于最近工程需要将单片机数据显示,Qt自己画太麻烦,查到Qt自带chart模块,这样可以省不少时间,因此记录一下使用过程。
- 模块添加
在.pro文件中添加:QT += charts - 引用
在mainwindow.cpp中添加:
#include <QtCharts>
using namespace QtCharts;
- 使用
在构造函数中添加:
QChart *chart = new QChart(); //创建QChart实例,为图表框架,相当图画笔
QChartView *chartview = new QChartView(chart);//用于显示曲线,相当于画布
this->setCentralWidget(chartview); //将图表显示在整个窗口
若运行后没有错误,则说明添加成功,下面我们举一个具体例子。
- 例子
.pro文件
#-------------------------------------------------
#
#Project created by QtCreator 2019-02-20T11:47:28
#
#-------------------------------------------------
QT += core gui charts
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled1
TEMPLATE = app
#The following define makes your compiler emit warnings if you use
#any feature of Qt which has been marked as deprecated (the exact warnings
#depend on your compiler). Please