I need to make a plot with a fixed aspect ratio. It seems that QwtPlotRescaler is intended for this too, but I cannot make it work at all. I made a very simple example:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
curve->setSamples(points);
curve->attach(plot);
// QwtPlotRescaler section start
QwtPlotRescaler *rescaler = new QwtPlotRescaler(plot->canvas());
rescaler
->setReferenceAxis
(QwtPlot::xBottom);
rescaler
->setAspectRatio
(QwtPlot::yLeft,
1.0);
rescaler->setRescalePolicy(QwtPlotRescaler::Expanding);
rescaler->setEnabled(true);
rescaler->rescale();
plot->plotLayout()->setAlignCanvasToScales(true);
// QwtPlotRescaler section end
this->setCentralWidget(plot);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setLayout(new QVBoxLayout(this));
QwtPlot *plot = new QwtPlot(this);
QwtPlotCurve *curve = new QwtPlotCurve();
QPolygonF points;
points.append(QPointF(0, 0));
points.append(QPointF(1, 1));
curve->setSamples(points);
curve->attach(plot);
// QwtPlotRescaler section start
QwtPlotRescaler *rescaler = new QwtPlotRescaler(plot->canvas());
rescaler->setReferenceAxis(QwtPlot::xBottom);
rescaler->setAspectRatio(QwtPlot::yLeft, 1.0);
rescaler->setRescalePolicy(QwtPlotRescaler::Expanding);
rescaler->setEnabled(true);
rescaler->rescale();
plot->plotLayout()->setAlignCanvasToScales(true);
// QwtPlotRescaler section end
this->setCentralWidget(plot);
}
To copy to clipboard, switch view to plain text mode
Without QwtPlotRescaler section I get what I expect: a simple plot with a single straight line going from (0, 0) to (1, 1) and two axes, both from 0 to 1. After adding QwtPlotRescaler section I get an empty plot - no line, no axes, no ticks.
Bookmarks