ok, I had to set the initial range for yRight as well (I'm doing it manually) and then the following works:
connect(axisWidget(yLeft), SIGNAL(scaleDivChanged()), this, SLOT(updateRightScale()));
updateRightScale();
connect(axisWidget(xBottom), SIGNAL(scaleDivChanged()), this, SLOT(updateTopScale()));
updateTopScale();
connect(axisWidget(yLeft), SIGNAL(scaleDivChanged()), this, SLOT(updateRightScale()));
updateRightScale();
connect(axisWidget(xBottom), SIGNAL(scaleDivChanged()), this, SLOT(updateTopScale()));
updateTopScale();
To copy to clipboard, switch view to plain text mode
void Plot::updateRightScale() {
axisWidget(yRight)->setScaleDiv(axisScaleEngine(yLeft)->transformation(), *axisScaleDiv(yLeft));
}
void Plot::updateTopScale() {
axisWidget(xTop)->setScaleDiv(axisScaleEngine(xBottom)->transformation(), *axisScaleDiv(xBottom));
}
void Plot::updateRightScale() {
axisWidget(yRight)->setScaleDiv(axisScaleEngine(yLeft)->transformation(), *axisScaleDiv(yLeft));
}
void Plot::updateTopScale() {
axisWidget(xTop)->setScaleDiv(axisScaleEngine(xBottom)->transformation(), *axisScaleDiv(xBottom));
}
To copy to clipboard, switch view to plain text mode
thanks! I was just thinking there might be a way to tell the PlotScaleWidget(yRight) to get its actuall data directly from yLeft.
Simon
Added after 23 minutes:
hmm, that's still not working perfectly. I have two problems:
1. when I use QwtPlotZoomer, left and right axis get out of sync
2. I have some code that does not actually display the plot, but just writes it to an image file. There xBottom and yTop are out of sync. The code is quite simple:
Plot plot;
plot.setTitle(m_iqeCurveName);
axisFont.setPointSize(14);
axisFont.setBold(true);
plot.
setAxisFont(QwtPlot::xBottom, axisFont
);
plot.
setAxisFont(QwtPlot::yLeft, axisFont
);
PlotCurve rMeasCurve;
rMeasCurve.update(m_R_meas);
rMeasCurve.setEnabled(true);
rMeasCurve.setPlot(&plot);
rMeasCurve.setName("R_meas");
rMeasCurve.setColor(Qt::green);
rMeasCurve.setLineWidth(2);
plot.setDefaultRange(250, 1200, 0, 1.1);
plot.replot();
plot.saveImage(outputDir.absoluteFilePath("R/R "+ ID + ".png"));
Plot plot;
plot.setTitle(m_iqeCurveName);
QFont axisFont = plot.axisFont(QwtPlot::xBottom);
axisFont.setPointSize(14);
axisFont.setBold(true);
plot.setAxisFont(QwtPlot::xBottom, axisFont);
plot.setAxisFont(QwtPlot::yLeft, axisFont);
PlotCurve rMeasCurve;
rMeasCurve.update(m_R_meas);
rMeasCurve.setEnabled(true);
rMeasCurve.setPlot(&plot);
rMeasCurve.setName("R_meas");
rMeasCurve.setColor(Qt::green);
rMeasCurve.setSymbol(QwtSymbol::NoSymbol);
rMeasCurve.setLineWidth(2);
plot.setDefaultRange(250, 1200, 0, 1.1);
plot.replot();
plot.saveImage(outputDir.absoluteFilePath("R/R "+ ID + ".png"));
To copy to clipboard, switch view to plain text mode
with the following for setDefaultRange:
void Plot::setDefaultRange(double minX, double maxX, double minY, double maxY) {
setAxisScale
(QwtPlot::xBottom, minX, maxX
);
setAxisScale
(QwtPlot::xTop, minX, maxX
);
setAxisScale
(QwtPlot::yLeft, minY, maxY
);
setAxisScale
(QwtPlot::yRight, minY, maxY
);
replot();
m_zoomer->setZoomBase(false); // setzt den aktuellen Zoom als Standard?
}
void Plot::setDefaultRange(double minX, double maxX, double minY, double maxY) {
setAxisScale(QwtPlot::xBottom, minX, maxX);
setAxisScale(QwtPlot::xTop, minX, maxX);
setAxisScale(QwtPlot::yLeft, minY, maxY);
setAxisScale(QwtPlot::yRight, minY, maxY);
replot();
m_zoomer->setZoomBase(false); // setzt den aktuellen Zoom als Standard?
}
To copy to clipboard, switch view to plain text mode
Any ideas?
Bookmarks