我正在使用QCustom Pplot在qt中生成图形,但是即使在设计选项卡中最大化小部件大小之后,生成的图形对于我的目的来说也太小了。有没有办法使图形/绘图全屏?当我运行代码并最大化 gui 窗口时,绘图本身的大小保持不变。
void Cpp_Fire::on_manual_fire_clicked()
{
// Code for graph
// generate some data:
QVector<double> x(variables.nr_samples), y(variables.nr_samples);
for (int i=0; i<variables.nr_samples; ++i)
{
x[i] = x_axis[i];
y[i] = y_axis[i];
}
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(x, y);
ui->customPlot->xAxis->setLabel("x");
ui->customPlot->yAxis->setLabel("y");
ui->customPlot->xAxis->setRange(x[0], x[variables.nr_samples-1]);
ui->customPlot->yAxis->setRange(0, 65000);
ui->customPlot->replot();
}
要全屏设置 Qcustomplot 窗口:
setGeometry(QApplication::desktop()->screenGeometry()); /* in your QMainWindow derivative constructor */
现在,您的图表必须自动缩放:
ui->customPlot->rescaleAxes(); /* after the graph data is filled */
如果还不够,您可以随时添加缩放或拖动图形的功能,以获得您喜欢的视图:
ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);