Originally Posted by
Uwe
Then QwtPlotPicker is exactly what you are looking for.
All you need to do is to use the machine above and configure a vertical line as rubberband and enable the tracker text to AlwaysOn. Then overload QwtPlotPicker::trackerTextF where you calculate the corresponding y value for the curve ( or several curves ):
{
{
}
}
class YourPicker: public QwtPlotPicker
{
virtual QwtText trackerTextF( const QPointF &pos ) const
{
return QwtPlotPicker::trackerTextF( x, findCurvePos( pos.x() );
}
}
To copy to clipboard, switch view to plain text mode
How to implement findCurvePos in an effective way depends on the characteristics of your samples. F.e when your samples are ordered in x direction you could use some binary search algorithm ( if this is what you need I can post code lying on my disk ).
Uwe
1. How for QwtPlotPicker I can draw more than one Text? I need for each curve text with value Y
2. Can I control QwtPlotPicker? What I mean? I have 2 plots. than I want when I move QwtPlotPicker at plot 1 I need to move automatically move QwtPlotPicker at plot 2?
3. How can I set position of VLine of Picker?
4. As I can see I cant control text of QwtPlotPicker?... I dont see how I can do f.e. red backgroud and white letter for text of QwtPlotPicker...
If I can do this, than this way suits me and I will thanks if U post code how to implement findCurvePos...
And can U tell me why dont work QwtPlotMarker with QwtPlotOverlay like I show code above?
Mb to do this task will be better to draw VLine by painter on QwtPlotOverlay and using QwtText for show value of Y for each curve? If it is more prefer way, can I draw QwtText not into rectangle? f.e. into circle or another shape that I want?
F.e.:
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QDebug>
class Widget;
class Picker;
{
Q_OBJECT
public:
explicit Widget
(QWidget *parent
= 0);
~Widget();
private:
Picker *m_picker1; // for m_plot1
Picker *m_picker2; // for m_plot2
};
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QDebug>
class Widget;
class QVBoxLayout;
class QwtPlot;
class Picker;
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private:
QVBoxLayout *m_layout;
QwtPlot *m_plot1;
QwtPlot *m_plot2;
Picker *m_picker1; // for m_plot1
Picker *m_picker2; // for m_plot2
};
To copy to clipboard, switch view to plain text mode
#include "widget.h"
#include <QWidget>
#include <QVBoxLayout>
#include "plot.h"
#include "picker.h"
{
m_layout->setMargin(0);
m_layout->addWidget(m_plot1);
m_layout->addWidget(m_plot2);
m_picker1 = new Picker(m_plot1->canvas());
m_picker2 = new Picker(m_plot2->canvas());
connect(m_picker1,
SIGNAL(moved
(QPoint)),
m_picker2,
SLOT(slot_move
(QPoint)));
connect(m_picker2,
SIGNAL(moved
(QPoint)),
m_picker1,
SLOT(slot_move
(QPoint)));
setLayout(m_layout);
}
Widget::~Widget()
{
}
#include "widget.h"
#include <QWidget>
#include <QVBoxLayout>
#include "plot.h"
#include "picker.h"
Widget::Widget(QWidget *parent) :
QWidget(parent)
{
m_layout = new QVBoxLayout(this);
m_layout->setMargin(0);
m_plot1 = new QwtPlot(this);
m_plot2 = new QwtPlot(this);
m_layout->addWidget(m_plot1);
m_layout->addWidget(m_plot2);
m_picker1 = new Picker(m_plot1->canvas());
m_picker2 = new Picker(m_plot2->canvas());
connect(m_picker1, SIGNAL(moved(QPoint)),
m_picker2, SLOT(slot_move(QPoint)));
connect(m_picker2, SIGNAL(moved(QPoint)),
m_picker1, SLOT(slot_move(QPoint)));
setLayout(m_layout);
}
Widget::~Widget()
{
}
To copy to clipboard, switch view to plain text mode
#ifndef PICKER_H
#define PICKER_H
#include <qwt/qwt_plot_picker.h>
{
Q_OBJECT
public:
explicit Picker
(QWidget *parent
= 0);
signals:
public slots:
void slot_move
(const QPoint &pos
);
};
#endif // PICKER_H
#ifndef PICKER_H
#define PICKER_H
#include <qwt/qwt_plot_picker.h>
class Picker : public QwtPlotPicker
{
Q_OBJECT
public:
explicit Picker(QWidget *parent = 0);
signals:
public slots:
void slot_move(const QPoint &pos);
};
#endif // PICKER_H
To copy to clipboard, switch view to plain text mode
#include "picker.h"
#include <qwt/qwt_picker_machine.h>
{
setRubberBandPen
(QColor(Qt
::magenta));
setTrackerPen
(QColor(Qt
::darkRed));
setTrackerFont
(QFont("Helvetica"));
setStateMachine(new QwtPickerTrackerMachine);
}
void Picker
::slot_move(const QPoint &pos
) {
move(pos);
}
#include "picker.h"
#include <qwt/qwt_picker_machine.h>
Picker::Picker(QWidget *parent) :
QwtPlotPicker(parent)
{
setRubberBandPen(QColor(Qt::magenta));
setRubberBand(QwtPicker::VLineRubberBand);
setTrackerPen(QColor(Qt::darkRed));
setTrackerMode(QwtPicker::AlwaysOn);
setTrackerFont(QFont("Helvetica"));
setStateMachine(new QwtPickerTrackerMachine);
}
void Picker::slot_move(const QPoint &pos)
{
move(pos);
}
To copy to clipboard, switch view to plain text mode
Bookmarks