QwtPlotPicker stay visible after DoubleMouseClick
Hello,
i use in my QwtPlot a curve tracker like in the playground example "CurveTracker".
Code:
#include "curvetracker.h"
#include <qwt_picker_machine.h>
#include <qwt_series_data.h>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
struct compareX
{
inline bool operator
()( const double x,
const QPointF &pos
) const {
return ( x < pos.x() );
}
};
CurveTracker
::CurveTracker( QWidget *canvas
):{
setRubberBand( VLineRubberBand );
}
QRect CurveTracker
::trackerRect( const QFont &font
) const {
// align r to the first curve
const QwtPlotItemList curves
= plot
()->itemList
( QwtPlotItem::Rtti_PlotCurve );
if ( curves.size() > 0 )
{
QPointF pos
= invTransform
( trackerPosition
() );
const QLineF line
= curveLineAt
( if ( !line.isNull() )
{
const double curveY = line.pointAt(
( pos.x() - line.p1().x() ) / line.dx() ).y();
pos.setY( curveY );
pos = transform( pos );
r.moveBottom( pos.y() );
}
}
return r;
}
{
trackerText.setColor( Qt::black );
trackerText.
setBorderPen( QPen( c,
2 ) );
c.setAlpha( 200 );
trackerText.setBackgroundBrush( c );
const QwtPlotItemList curves =
for ( int i = 0; i < curves.size(); i++ )
{
const QString curveInfo
= curveInfoAt
(
if ( !curveInfo.isEmpty() )
{
if ( !info.isEmpty() )
info += "<br>";
info += curveInfo;
}
}
trackerText.setText( info );
return trackerText;
}
{
const QLineF line
= curveLineAt
( curve, pos.
x() );
if ( line.isNull() )
const double y = line.pointAt(
( pos.x() - line.p1().x() ) / line.dx() ).y();
QString info
( "<font color=""%1"">%2</font>" );
return info.arg( curve->pen().color().name() ).arg( y );
}
QLineF CurveTracker
::curveLineAt( {
if ( curve->dataSize() >= 2 )
{
const QRectF br
= curve
->boundingRect
();
if ( ( br.width() > 0 ) && ( x >= br.left() ) && ( x <= br.right() ) )
{
int index = qwtUpperSampleIndex<QPointF>(
*curve->data(), x, compareX() );
if ( index == -1 &&
x == curve->sample( curve->dataSize() - 1 ).x() )
{
// the last sample is excluded from qwtUpperSampleIndex
index = curve->dataSize() - 1;
}
if ( index > 0 )
{
line.setP1( curve->sample( index - 1 ) );
line.setP2( curve->sample( index ) );
}
}
}
return line;
}
This works and i get always the values from the actual Mouse Position.
Now i want to double Click at a selected position and want the tracker to stay visible also when i move the mouse outside the plot area.
How can i manage this?
Thanks for help
DSP
Re: QwtPlotPicker stay visible after DoubleMouseClick
This first step is to terminate the picker on double clicks, what can be done by overloading the transition() method of your QwtPickerMachine. Have a look at the code in qwt_picker_machine.cpp and you will know what to do.
Then I would connect a slot to the QwtPlotPicker::selected signal, where you simply insert a QwtPlotMarker at the selected position, that looks like the cursor of the picker.
Uwe
Re: QwtPlotPicker stay visible after DoubleMouseClick
Hi Uwe,
sorry i didn't get it.
My CurveTracker class is derived from QwtPlotPicker.
Where should i overload the transition function from QwtPickerMachine class?
Do i have to write a own MyPickerMachine class and handle all the stuff there?
Then i could overload the transistion function and could try to catch the double click event.
Who does emit the selected signal?
Thanks for further explanations
Re: QwtPlotPicker stay visible after DoubleMouseClick
Quote:
Originally Posted by
DSP
My CurveTracker class is derived from QwtPlotPicker.
Where should i overload the transition function from QwtPickerMachine class?
Inherit from whatever machine your picker is using ( in the curvetracker example it is a QwtPickerDragPointMachine ), extend/configure it by overloading its virtual methods ad then add it with:
Code:
yourPicker->setStateMachine( yourStateMachine )
Of course you can also write your own state machine from scratch if you prefer that.
Quote:
Who does emit the selected signal?
Well a picker is for selecting points/rects/polygons ( in your case a point ) and the selected signal emits the result of the selection, what should contain the position, where to insert the marker.
Uwe