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:
Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) :
  2. QMainWindow(parent),
  3. ui(new Ui::MainWindow)
  4. {
  5. ui->setupUi(this);
  6. this->setLayout(new QVBoxLayout(this));
  7. QwtPlot *plot = new QwtPlot(this);
  8.  
  9. QwtPlotCurve *curve = new QwtPlotCurve();
  10. QPolygonF points;
  11. points.append(QPointF(0, 0));
  12. points.append(QPointF(1, 1));
  13. curve->setSamples(points);
  14. curve->attach(plot);
  15.  
  16. // QwtPlotRescaler section start
  17. QwtPlotRescaler *rescaler = new QwtPlotRescaler(plot->canvas());
  18. rescaler->setReferenceAxis(QwtPlot::xBottom);
  19. rescaler->setAspectRatio(QwtPlot::yLeft, 1.0);
  20. rescaler->setRescalePolicy(QwtPlotRescaler::Expanding);
  21. rescaler->setEnabled(true);
  22. rescaler->rescale();
  23. plot->plotLayout()->setAlignCanvasToScales(true);
  24. // QwtPlotRescaler section end
  25.  
  26. this->setCentralWidget(plot);
  27. }
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.