qt使用qwt 跟随鼠标显示坐标
作者:互联网
头文件
#include <qwt_plot_canvas.h> #include <qwt_plot_layout.h> #include <qwt_plot_picker.h> #include <qwt_picker_machine.h> #include <qwt_painter.h> #include <qwt_plot.h> #include <qwt_plot_curve.h> #include <qwt_plot_marker.h> #include <qwt_plot_grid.h> #include <qwt_plot_magnifier.h> #include <qwt_plot_panner.h> #include <qwt_legend.h> #include <qwt_plot_directpainter.h> #include <qwt_series_data.h> #include <qwt_symbol.h> #include <qwt_interval.h> #include <qwt_date_scale_draw.h> #include <qwt_plot_zoomer.h> #include <qwt_plot_renderer.h>//保存用
初始化时候
picker_01 = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,ui->plot_temp->canvas()); picker_01->setStateMachine(new QwtPickerDragPointMachine()); picker_01->setRubberBandPen(QColor(Qt::blue));//线的颜色 picker_01->setRubberBand(QwtPicker::CrossRubberBand); picker_01->setTrackerMode(QwtPicker::AlwaysOn);//被激活时候显示 picker_01->setTrackerPen(QColor(Qt::black));//字的颜色
注意在获取selected时候我使用两种方式,一种是直接旧的connect方式,一种lambda方式,经过测试lambda方式失败
connect(picker_01,QOverload<const QPointF & >::of(&QwtPlotPicker::selected),this,[=](const QPointF &pos){ QString info; info.sprintf("x:%d y:%d",pos.x(),pos.y()); myDebugMsg(info); // });//失败 //void selected( const QPolygon &polygon ) connect(picker_01,QOverload<const QPolygon & >::of(&QwtPicker::selected),this,[=](const QPolygon &pos){ //QString info="test"; //info.sprintf("x:%d y:%d",pos.x(),pos.y()); //myDebugMsg(info); QPoint point = ui->plot_temp->canvas()->mapFromGlobal(QCursor::pos()); QString info = QString("x = %1, y = %2").arg(ui->plot_temp->invTransform(QwtPlot::xBottom,point.x())).arg(ui->plot_temp ->invTransform(QwtPlot::yLeft,point.y()) ); myDebugMsg(info); });//失败 //testslot
使用旧版connect方式成功
connect( picker_01, SIGNAL( selected( const QPolygon & ) ), SLOT( testslot( const QPolygon & ) ) ); connect( picker_01, SIGNAL( selected( const QPointF & ) ), SLOT( testslot2( const QPointF & ) ) );
void testslot(const QPolygon &pos){ //QPoint point = ui->plot_monitoring->canvas()->mapFromGlobal(QCursor::pos()); //QString info = QString("x = %1, y = %2").arg(ui->plot_monitoring->invTransform(QwtPlot::xBottom,point.x())).arg(ui->plot_monitoring ->invTransform(QwtPlot::yLeft,point.y()) ); QString info = "test"; myDebugMsg(info); } void testslot2(const QPointF &pos){ QString info; info.sprintf("x:%f y:%f",pos.x(),pos.y()); myDebugMsg(info); }
、、喵喵个熊
标签:info,picker,qwt,const,qt,pos,01,include,鼠标 来源: https://www.cnblogs.com/RYSBlog/p/16448437.html