QCustomPlot Discussion and Comments

Graph with equal axis sizes (square)Return to overview

Hi!
Trying to make an independent of scale of main widget size square graph.

mainwindow.cpp:

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){
    ui->setupUi(this);

    ui->graph = new QCustomPlot;
    ui->graph->addGraph();
    ui->graph->xAxis->setRange(-2000, 2000);
    ui->graph->yAxis->setRange(-2000, 2000);
}
void MainWindow::resizeEvent(QResizeEvent *event){
    QCPAxis *x, *y;
    x = ui->graph->axisRect()->axis(QCPAxis::atBottom);
    y = ui->graph->axisRect()->axis(QCPAxis::atLeft);
    y->setScaleRatio(x, 1.0);
    ui->graph->replot();
}

But this method is not working for me,

graph is a child of form expanded centralWidget

Is it possible? Any advice?