Hi all,
i want to print a plot as pdf and everything is working fine. My problem is to set an output directory for my pdf. I could'nt find a method like setOutputDirectory for QPrinter. Using getSaveFileName, i can set a directory but if i change the directory using the file dialog, my pdf is still saved at the chosen working directory of my getSaveFileName method.
void GraphicTools::printPDF()
{
filter.setOptions(options);
QPixmap pixmap
(ui.
qwtPlot->size
());
pixmap.fill(Qt::transparent);
if(!pixmap.isNull())
{
savingDirectory, tr("(PDF Files)*.pdf"));
QString savingDirectory
= strippedPathName
(fileName
);
if (!fileName.isEmpty())
{
printer.
setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(strippedName(fileName));
ui.qwtPlot->print(printer, filter);
QMessageBox::information(this, tr
("PDF was saved at..."),
tr("%1 was saved at %2").arg(strippedName(fileName), savingDirectory),
}
}
}
void GraphicTools::printPDF()
{
QwtPlotPrintFilter filter;
int options = QwtPlotPrintFilter::PrintAll;
options &= ~QwtPlotPrintFilter::PrintBackground;
options |= QwtPlotPrintFilter::PrintFrameWithScales;
filter.setOptions(options);
QPrinter printer(QPrinter::HighResolution);
QPixmap pixmap(ui.qwtPlot->size());
pixmap.fill(Qt::transparent);
if(!pixmap.isNull())
{
QString savingDirectory = QDir::currentPath();
QString fileName = QFileDialog::getSaveFileName(this, tr("Save the file as PDF"),
savingDirectory, tr("(PDF Files)*.pdf"));
QString savingDirectory = strippedPathName(fileName);
if (!fileName.isEmpty())
{
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(strippedName(fileName));
ui.qwtPlot->print(printer, filter);
QMessageBox::information(this, tr("PDF was saved at..."),
tr("%1 was saved at %2").arg(strippedName(fileName), savingDirectory),
QMessageBox::Ok);
}
}
}
To copy to clipboard, switch view to plain text mode
Thanks for any advices.
Bookmarks