关于QCustomPlot的绘图

该类可完成2D图形的绘制,下载地址为: http://www.qcustomplot.com/index.php/download,推荐下载最上面一个的首个文件,里面有类,还有代码可以参考。
这个类我上传至 http://download.csdn.net/detail/zhulichen/9783916,大家可以下载下来使用
自己先新建一个工程,并将qcustomplot.h与qcustomplot.cpp拷贝到目录工程下,然后将该两个文件添加至工程中。同时需要在.pro文件 QT +=widgets 后面添加printsupport

在.ui界面中拖入一个widget区域,选中widget区域点击右键,选择“提升为”按钮,将提成的类名称。
现在运行下,将出现了简单的坐标系,该坐标系默认的坐标为(0,5)(0,5)
很多文章中显示的都是画线,我在这里写的程序是显示点,每次可以输入一个点,然后显示在坐标系。
在.h头文件中添加函数:
public :
    void updateWidgetShow(QCustomPlot *customPlot);
    QPointF inputPoint(float x,float y);
在.cpp文件中添加
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qcustomplot.h"
 
 
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    updateWidgetShow(ui->widget);
}
 
 
MainWindow::~MainWindow()
{
    delete ui;
}
 
 
void MainWindow::updateWidgetShow(QCustomPlot *customPlot)
{
    customPlot->clearGraphs();
    customPlot->setBackground(QPixmap("./background.jpg"));
    //customPlot->axisRect()->setBackground(QPixmap("./background.jpg"));
    customPlot->addGraph();
    customPlot->graph()->setLineStyle(QCPGraph::lsNone);
    customPlot->graph()->setScatterStyle(QCPScatterStyle(QPixmap("./sun.png")));
    QPointF label=inputPoint(5.9,2.3);
    QVector<double> xx(1),yy(1);
    xx[0]=label.x();
    yy[0]=label.y();
    customPlot->graph()->addData(xx,yy);
    customPlot->replot();
    customPlot->xAxis->setRange(0,10);
    customPlot->yAxis->setRange(0,10);
}
 
 
QPointF MainWindow::inputPoint(float x, float y)
{
    QPointF point;
    point.setX(x);
 
 
    point.setY(y);
    return point;
}
 
 
 运行一下,结果如下图所示: 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值