Tool tip to show plot values in Qwt

2019-03-27 11:52发布

问题:

I have a qwt plot in my application. I want to show a small tool tip to show the value of the point at which mouse is pointed on the curve. I found that I have to use QwtPlotPicker for this, but couldn't find any proper example to implement this in my code. I am new to Qwt so it would be great if anyone could help me solve this problem.

Thanks, Rakesh.

回答1:

The author himself says here:

A QwtPlotPicker gives you the current position of the mouse ( in screen and plot coordinates ). Then you need to find the closest points of your curves. You can use QwtPlotCurve::closestPoint(), but in most cases you can find a much faster implementation depending on the characteristics of your data. When you need to compare the mouse position with the lines between the points you need the pixel position of these points ( use QwtPlot::canvasMap ). Maybe looking at the CanvasPicker of the eventfilter example helps.

I implemented it in my own class, which is a subclass of QwtPlot. In the constructor I have the following:

QwtPlotPicker* plotPicker = new QwtPlotPicker(this->xBottom, this->yLeft, QwtPicker::CrossRubberBand, QwtPicker::AlwaysOn, this->canvas());
QwtPickerMachine* pickerMachine = new QwtPickerClickPointMachine();
plotPicker->setStateMachine(pickerMachine);
connect(plotPicker, SIGNAL(selected(const QPointF&)), this, SLOT(onSelected(const QPointF&)));

Now in my class (where the this pointer refers to) I should implement the slot onSelected(const QPointF&) which will give the plot coordinates.



标签: c++ qwt