Qtchart教程

Qtchart教程

由于最近工程需要将单片机数据显示,Qt自己画太麻烦,查到Qt自带chart模块,这样可以省不少时间,因此记录一下使用过程。

  1. 模块添加
    在.pro文件中添加:QT += charts
  2. 引用
    在mainwindow.cpp中添加:
#include <QtCharts>
using namespace QtCharts;
  1. 使用
    在构造函数中添加:
QChart *chart = new QChart();  //创建QChart实例,为图表框架,相当图画笔
QChartView *chartview = new QChartView(chart);//用于显示曲线,相当于画布
this->setCentralWidget(chartview);  //将图表显示在整个窗口

若运行后没有错误,则说明添加成功,下面我们举一个具体例子。

  1. 例子

.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
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值