qwtplot

-----------------------------------------------------------------基本设置    
ui->qwtPlot->setCanvasBackground(Qt::white);//设置背景颜色
    ui->qwtPlot->setAxisScale(QwtPlot::yLeft,-2,55,2);//设置y轴坐标
    ui->qwtPlot->setAxisTitle(QwtPlot::yLeft,tr("速度(km/h)"));//设置y轴标题
    ui->qwtPlot->setAxisTitle(QwtPlot::xBottom,tr("时间(s)"));//设置x轴标题
    ui->qwtPlot->setAxisScale(QwtPlot::xBottom,0,195,1);//设置x轴坐标
    //ui->qwtPlot->setAxisLabelAlignment(QwtPlot::xBottom,Qt::AlignHCenter);
    //ui->qwtPlot->setAxisFont(QwtPlot::xBottom,QFont("Times",18,QFont::Bold));//设置坐标字体
    //ui->qwtPlot->setAxisLabelRotation(QwtPlot::xBottom,90);
    //ui->qwtPlot->setWindowTitle("aaaaaaaaaaaa");//设置qwt标题


-------------------------------------------------------------画线
QwtPlotCurve *curve = new QwtPlotCurve();//设置画曲线工具
urve->setPen( Qt::blue, 1 ,Qt::DotLine);//设置画笔颜色和线条样式
QPolygonF pointsh,pointsl,points;//绘制路径
curve->setSamples( points );
curve->setRenderHint(QwtPlotItem::RenderAntialiased,true);//抗锯齿渲染
curve->attach( ui->qwtPlot );
---------------------------------------------------------------
ui->qwtPlot->updateAxes();//通知坐标更新
ui->qwtPlot->replot();//重新绘制图线


------------------------------------------------------------------------网络资源,未验证
//增加网格   
 QwtPlotGrid *grid = new QwtPlotGrid;  
 grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));  
 grid->attach(this); 


//增加缩放功能   
QwtPlotZoomer  *pZoomer= new QwtPlotZoomer(canvas());   
pZoomer->setRubberBandPen(QPen(Qt::red)); 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你正在使用 QwtPlot 库,可以通过以下步骤实现游标移动: 1. 创建一个 QwtPlotMarker 对象来表示游标。 2. 将游标添加到 QwtPlot 中。使用 QwtPlot::insertMarker() 或 QwtPlot::addMarker() 方法来添加游标。 3. 捕获鼠标移动事件,并在事件处理程序中更新游标位置。 以下是示例代码: ```cpp // 创建游标对象 QwtPlotMarker *cursor = new QwtPlotMarker(); cursor->setLineStyle(QwtPlotMarker::VLine); cursor->setLinePen(Qt::black); cursor->setXValue(0.0); // 初始位置 // 将游标添加到 QwtPlot cursor->attach(qwtPlot); // 捕获鼠标移动事件 qwtPlot->canvas()->installEventFilter(this); // 处理鼠标移动事件 bool MyWidget::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::MouseMove && obj == qwtPlot->canvas()) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); // 将鼠标位置转换为坐标系值 double x = qwtPlot->invTransform(QwtPlot::xBottom, mouseEvent->pos().x()); double y = qwtPlot->invTransform(QwtPlot::yLeft, mouseEvent->pos().y()); // 更新游标位置 cursor->setXValue(x); cursor->setYValue(y); // 重新绘制 QwtPlot qwtPlot->replot(); } return false; } ``` 这段代码创建了一个垂直线样式的游标对象,并将其添加到 QwtPlot 中。然后,它捕获 QwtPlot 的鼠标移动事件,并在事件处理程序中更新游标位置。请注意,这里使用了 QwtPlot::invTransform() 方法将鼠标位置转换为坐标系值。最后,调用 QwtPlot::replot() 方法重新绘制 QwtPlot

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值