技术专栏
QCustomPlot的设置和使用
下载链接:http://www.qcustomplot.com/index.php/download
博主使用的是1.3.2的版本,最新的2.0的版本中有很多的东西已经更新,官方的使用说明存在出入,所以此次使用的是1.3.2的版本。
将下载好的文件解压,qcustomplot.cpp 和qcustomplot.h这两个文件,放入我们创建的工程里面。
下载的解压文件中有相应的example。可以先查看相应的PLOTS的工程文件。在QT中打开项目工程plot-examples.pro,进行查看可编译。
在自己创建的工程中:
customPlot = new QCustomPlot();
QVBoxLayout *vbox = new QVBoxLayout();
vbox->addWidget(customPlot);
vbox->setSpacing(0);
vbox->setContentsMargins(0,0,0,0);
- 1
- 2
- 3
- 4
- 5
先设置一下控件,以及设置布局方式。
customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables);
这部分是设置鼠标点击,鼠标滑轮,区域设置,标题设置等,可选的设置。
customPlot->setInteractions(QCP::iSelectLegend);
//设置折线等的设置
customPlot->axisRect()->setupFullAxesBox();
//区域填充满坐标轴
customPlot->legend->setVisible(true);
//折现描述的区域模块显示
QFont legendFont = font();
legendFont.setPointSize(20);
//设置字体大小
customPlot->legend->setFont(legendFont);
customPlot->xAxis->setTickLabelFont(legendFont);
customPlot->yAxis->setTickLabelFont(legendFont);
//设置XY轴字体大小
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
// 设置xy轴内的模式:
customPlot->addGraph();
customPlot->graph()->setLineStyle((QCPGraph::LineStyle::lsLine));
- 1
- 2
// 设置线的模式
customPlot->graph()->setScatterStyle(QCPScatterStyle::ScatterShape::ssDisc);
//设置线的节点的
QPen graphPen;
graphPen.setColor(QColor(Qt::red));
graphPen.setWidthF(3);
customPlot->graph()->setPen(graphPen);
//设置线的颜色,宽度,以及画笔
customPlot->xAxis->setRange(0, 10);
customPlot->xAxis->setAutoTickStep(false);
customPlot->xAxis->setTickStep(3);
customPlot->xAxis->setAutoSubTicks(false);
customPlot->xAxis->setSubTickCount(3-1);
customPlot->yAxis->setRange(0, 5);
customPlot->yAxis->setAutoTickStep(false);
customPlot->yAxis->setTickStep(1);
// customPlot->yAxis->setSubTickCount(1);
customPlot->xAxis->setLabel("x_str");
customPlot->yAxis->setLabel("y_str");
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
<
//设置X轴和Y轴的范围
//设置XY轴的间隔的时候,需要先把自动设置间隔的关闭,然后手动设置。
//XY轴的标签也需要设置名称。
QVector<double> x, y;
y << 0<< 2 << 3 << 5 << 7 << 3 << 8 << 2<<5;
x <<0<< 3<< 6 << 9 << 12 << 15 << 18 << 21 <<24;
customPlot->graph()->setData(x, y);
customPlot->replot();
- 1
- 2
- 3
- 4
- 5
设置数据的时候,需要用到QVector,然后将数据存入,一个一个的显示。
在调用完之后需要使用customPlot->replot();将数据更新到坐标轴上去。
声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包
点赞
收藏
评论
打赏
- 分享
- 举报
评论
0个
手气红包

相关专栏
-
浏览量:2962次2020-05-14 17:30:06
-
浏览量:2973次2020-08-23 20:59:44
-
浏览量:17776次2021-01-29 19:22:55
-
浏览量:7650次2020-08-23 21:25:35
-
浏览量:5797次2020-08-23 21:17:12
-
浏览量:5692次2020-08-23 21:07:51
-
浏览量:5445次2020-05-08 15:46:11
-
浏览量:2904次2017-11-15 11:27:56
-
浏览量:3581次2020-05-07 19:43:16
-
浏览量:9345次2020-05-07 14:42:07
-
浏览量:9490次2020-12-16 11:31:02
-
浏览量:2994次2019-12-05 17:38:34
-
浏览量:2791次2017-11-22 11:51:03
-
浏览量:4320次2020-10-09 17:29:50
-
浏览量:2269次2020-09-16 19:14:51
-
浏览量:4091次2020-10-10 15:51:00
-
浏览量:1670次2024-01-12 15:38:50
-
浏览量:749次2023-12-21 10:38:07
-
浏览量:9367次2020-12-08 09:32:15
置顶时间设置
结束时间
删除原因
-
广告/SPAM
-
恶意灌水
-
违规内容
-
文不对题
-
重复发帖
打赏作者
big_anana
您的支持将鼓励我继续创作!
打赏金额:
¥1

¥5

¥10

¥50

¥100

支付方式:

举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
审核成功
发布时间设置
发布时间:
请选择发布时间设置
是否关联周任务-专栏模块
审核失败
失败原因
请选择失败原因
备注
请输入备注