QCustomPlot Discussion and Comments

Increasing the viewing area when resizing plotReturn to overview

Img
1-old(at the moment)
2-new(is required)

How to make that when resizing the widget schedule does not stretch[1], and would increase viewing area [2]?

Hi mrZurg,

this can be archieved with a overwrite of the wdigets resizeEvent your customplot is in. I tried to implement this idea. This code seems to be a good starting point:

void MainWindow::resizeEvent(QResizeEvent *event)
{
    double right = ui->customPlot->axisRect()->margins().right();
    double left = ui->customPlot->axisRect()->margins().left();

    if(event->oldSize().width() < 0)
        return;

    double factor = ( ((double)event->oldSize().width() - left - right ) / ui->customPlot->xAxis->range().size() );

    ui->customPlot->xAxis->setRange(
                ui->customPlot->xAxis->range().lower,
                ((double)event->size().width() - left - right )  / factor );
    ui->customPlot->replot();
}

However, this code is buggy. It only works for positive ranges and extends only the right side of the range.

~ Markus