Syncing many QwtPlots with QwtPlotPickers
I have many QwtPlot objects sharing the same points data in XY coordinates. There can be like 10 curves in one plot. I want display some curves in first plot window and some other curves in second, etc.
Each plot would have drawn their y-axis but there would be only one common x-axis. Plots are stacked vertically and I want one common vertical tracker .
I have some ideas but would this work ?
- each QwtPlot has QwtPlotPicker installed and can draw vertical tracker.
- each plot has slot for 'selected' signal from the picker
- when plot receives 'selected' from picker it sends same signal to other plots with same arguments (that contain position)
I think this could work if the plot sizes are exactly the same. Would it be better to have plot translate mouse point to curve's point in x-axis and send that info to others?
Re: Syncing many QwtPlots with QwtPlotPickers
I am going to try to create a top level container, vertical layout that can draw vertical line. I then map mouse events to children QwtPlot widgets... from there I should be able to draw tracker with curve values.
1 Attachment(s)
Re: Syncing many QwtPlots with QwtPlotPickers
Attachment 11968Ok, seems almost to be working:
Attachment 11968
Looks like my mapping is a little bit off. Mouse is a little left from the 0 point but it reads more than zero:
Here's the code I'm using
Code:
//global vertical line on top level widget that holds individual pots, picker for global point
this);
picker->setStateMachine(new QwtPickerTrackerMachine);
picker
->setTrackerMode
(QwtPicker::AlwaysOff);
picker
->setRubberBand
(QwtPicker::VLineRubberBand);
picker
->setRubberBandPen
(QColor(Qt
::blue));
connect(picker, SIGNAL(moved(const QPoint&)),this,SLOT(onMoved(const QPoint&)));
Code:
void MultiPlot
::onMoved(const QPoint &p
) {
QPoint global
= this
->mapToGlobal
(p
);
qDebug() << "onMoved" << p <<", global:" << global << "plot1 fromglobal: " << plot1->mapFromGlobal(global);
QPoint pos
=plot1
->mapFromGlobal
(global
);
//invTransform
xMap.invTransform( pos.x() ),
yMap.invTransform( pos.y() )
);
plot1Picker->onSelected(posF);
qDebug() << "posF=" << posF;
global= this->mapToGlobal(p);
qDebug() << "onMoved" << p <<", global:" << global << "plot2 fromglobal: " << plot2->mapFromGlobal(global);
QPoint pos2
=plot2
->mapFromGlobal
(global
);
//invTransform
xMap
= plot2
->canvasMap
( QwtPlot::xBottom );
yMap
= plot2
->canvasMap
( QwtPlot::yLeft );
xMap.invTransform( pos2.x() ),
yMap.invTransform( pos2.y() )
);
plot2Picker->onSelected(pos2F);
qDebug() << "pos2F=" << pos2F;
}