QCustomPlot Discussion and Comments

How do I resize QCustomPlot proportionally (like a square)?Return to overview

When the window width is changed, QCustomPlot is stretched.
I want QCustomPlot to show next data (which was previously outside of the program window). That is, to increase the QCustomPlot size proportionally (like a square).
How can I do this without affecting the QCustomPlot source codes?

You can set a specific aspect ratio between your axes during the resizeEvent. For example, I use something like this for displaying images (pixels need to remain square) :

void ImageWidget::resizeEvent(QResizeEvent *event) {
    QCustomPlot::resizeEvent(event);
    QCPAxis *x = m_imgAxis->axis(QCPAxis::atBottom);
    QCPAxis *y = m_imgAxis->axis(QCPAxis::atLeft);
    y->setScaleRatio(x, 1.0);
}

Hope it answers your question.

Vincent

Thank you!
I didn't need much, so the solution to the problem was pretty simple.

What I've done:

Step 1
Added to mainwindow.h:

  protected: virtual void resizeEvent(QResizeEvent *);
And in mainwindow.cpp:
void MainWindow::resizeEvent(QResizeEvent *event) {
    QCPAxis *x, *y;
    x = plotPresenter->customPlot->axisRect()->axis(QCPAxis::atBottom);
    y = plotPresenter->customPlot->axisRect()->axis(QCPAxis::atLeft);
    y->setScaleRatio(x, 1.0);
}
After this step, I saw some drawbacks when magnifying the screen. The next step corrected this.

Step 2
Added after

    y->setScaleRatio(x, 1.0);
line:
    plotPresenter->customPlot->replot();

Why did I do this?
Because resizeEvent is protected! I didn't want to use inheritance, since my task is rather small. And I also didn't want to change the QCustomPlot source code. And resizeEvent calls the replot function, which I inserted!
I have the QCustomPlot in a vertical layer.

Thanks again!

I forgot to write the following:
plotPresenter->customPlot is QCustomPlot