#include "qwt_plot_picker.h"
#include "qwt_picker_machine.h"
QwtPlotPicker *qwt_picker;//qwt管理鼠标事件
qwt_picker = new QwtPlotPicker(this->qwt_plot->canvas());
connect(qwt_picker, SIGNAL(appended(const QPoint &)), SLOT(append_his(const QPoint &)));
qwt_picker->setTrackerMode(QwtPicker::AlwaysOn); //跟踪模式
qwt_picker->setTrackerPen(QColor(Qt::yellow)); //跟踪显示字体颜色
//以下设置了点击之后按下出现的一些效果
//只有定义了它 才能设置对应的样式 比如想设置RectRubberBand必须先setStateMachine( new QwtPickerRectPointMachine() );
qwt_picker->setStateMachine(new QwtPickerDragPointMachine());
qwt_picker->setRubberBandPen(QColor(Qt::yellow)); //拾取器点击后样式颜色
qwt_picker->setRubberBand(QwtPicker::CrossRubberBand); //拾取器点击后样式
HisPicker->setStateMachine(new RXPickertMachine());
//可以发出点击和移动信号,连接可以做自己操作
connect(p3DPicker, SIGNAL(moved(const QPoint &)), SLOT(moved_d(const QPoint &)));
connect(p3DPicker, SIGNAL(appended(const QPoint &)), SLOT(append_d(const QPoint &)));
void DealQwtClass::append_his(const QPoint &a)
{
double x = this->qwt_plot->invTransform(QwtPlot::xBottom, a.x()); //获取到正确的关于坐标轴的数值
plotmark->setXValue(x);
this->qwt_plot->replot();
}
QPen pen_mark;
// QVector
// qreal space = 5;
// dashes << 3 << space << 3 << space;
//设置2毫米标记线
//pen_mark.setDashPattern(dashes);
pen.setStyle(Qt::SolidLine);
pen_mark.setColor(qRgb(255, 255,255));
pen_mark.setWidth(2);
plotmark->setLinePen(pen_mark);
plotmark->setLineStyle(QwtPlotMarker::VLine);
plotmark->setXValue(30);
//还能写文字信息
plotmark->setLabel(QString::fromUtf8("顾逸凡"));
plotmark->setLabelAlignment(Qt::AlignLeft); //这里发现个小技巧 plotmark->setLabelAlignment(Qt::AlignLeft|Qt::AlignBottom); 可以出现在左下 善于利用位运算符号
plotmark->setLabelOrientation(Qt::Vertical);
效果图
plotmark->attach(this->qwt_plot);
三.任何对象都可以设置Z轴,有覆盖关系,可以利用这点分层。