一、效果预览
默认保存路径:项目运行路径
二、代码示例
QCustomPlot提供了四种save的方式:
saveBmp(const QString &fileName, int width, int height, double scale, int resolution, QCP::ResolutionUnit resolutionUnit);
saveJpg(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit);
savePng(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit);
savePdf(const QString &fileName, int width, int height, QCP::ExportPen exportPen, const QString &pdfCreator, const QString &pdfTitle);
简易保存方式如图二:
CustomPlot->savePng("customPlot.png", 480, 320);
复杂保存方式:
// 获取程序运行路径
QString savePath = QCoreApplication::applicationDirPath() + "/output";
// 判断文件路径
if (isDirExist(savePath)) {
} else {
qDebug() << "保存文件目录未找到!";
QMessageBox::warning(this,
"warning",
"保存文件目录未找到!",
QMessageBox::Yes,
QMessageBox::Yes);
}
QString fileName = QFileDialog::getSaveFileName(this,
"保存波形数据", // 对话框的标题
savePath, // 保存的默认路径为程序运行路径
"Save Picture (*.png *jpg)"); // 打开文件的类型,;隔开
// 如果用户点击了“取消”按钮
if (fileName.isNull())
return;
// 保存图片
ui->customPlot->savePng(fileName, 1280, 800, 1.0, -1, 255);