QT中CustomPlot控件的使用

在使用CustomPlot控件之前需要先下载CustomPlot控件的。cpp和。h文件,当然里面也会有一些示例工程,工程中有详细的CustomPlot控件的使用方法,下面是CustomPlot的下载链接:
CustomPlot

CustomPlot的使用(直接代码介绍使用方法吧):

// 初始化
m_CustomPlot = new QCustomPlot;
// CustomPlot的基础功能设置
m_CustomPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iMultiSelect  | QCP::iSelectOther | QCP::iSelectItems);
// 基础功能共有以下几种,大体意思是:
// 1、轴可拖动     2、通过鼠标滚轮改变轴显示范围 3、用户可以选择多个对象,设定的修饰符(不是特别明白) 
// 4、图形是可选的  5、轴是可选的 6、图例是可选的。。。
/*enum Interaction { iRangeDrag         = 0x001 ///< <tt>0x001</tt> Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes)
                     ,iRangeZoom        = 0x002 ///< <tt>0x002</tt> Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes)
                     ,iMultiSelect      = 0x004 ///< <tt>0x004</tt> The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking
                     ,iSelectPlottables = 0x008 ///< <tt>0x008</tt> Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable)
                     ,iSelectAxes       = 0x010 ///< <tt>0x010</tt> Axes are selectable (or parts of them, see QCPAxis::setSelectableParts)
                     ,iSelectLegend     = 0x020 ///< <tt>0x020</tt> Legends are selectable (or their child items, see QCPLegend::setSelectableParts)
                     ,iSelectItems      = 0x040 ///< <tt>0x040</tt> Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem)
                     ,iSelectOther      = 0x080 ///< <tt>0x080</tt> All other objects are selectable (e.g. your own derived layerables, the plot title,...)
                 };*/
// 设置矩形边框
m_CustomPlot->axisRect()->setupFullAxesBox();
// 清空CustomPlot中的图形
m_CustomPlot->clearGraphs();
// 在CustomPlot中添加图形
m_CustomPlot->addGraph();
// 设置图形中的数据m_x和m_y是两个QVector容器
m_CustomPlot->graph(0)->setData(m_x, m_y);
// 这个是设置图形显示为合适范围(感觉设置的只是Y轴)
m_CustomPlot->graph(0)->rescaleValueAxis(true);
// 设置X轴的显示范围(这里是4条轴,x是下面那条,x2是上面那条,Y是先左后右)
m_CustomPlot->xAxis->setRange(m_x.at(0) - 1, m_x.at(m_x.size() - 1) + 1 );
// 刷新m_CustomPlot中数据
m_CustomPlot->replot();

大体就这些使用过程,如果还有其他不懂得,可以通过上面那个CustomPlot下载链接,了解更加详细的使用方法,如果是界面的话,可以通过将widget提升为CustomPlot,然后进入代码中后也需要先设置CustomPlot的属性才可以用。

猜你喜欢

转载自blog.csdn.net/bloke_come/article/details/79472285