Results 1 to 4 of 4

Thread: How to change the saving directory of a pdf printed plot?

  1. #1
    Join Date
    Oct 2008
    Location
    Aachen
    Posts
    20
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default How to change the saving directory of a pdf printed plot?

    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.

    Qt Code:
    1. void GraphicTools::printPDF()
    2. {
    3. int options = QwtPlotPrintFilter::PrintAll;
    4. options &= ~QwtPlotPrintFilter::PrintBackground;
    5. options |= QwtPlotPrintFilter::PrintFrameWithScales;
    6. filter.setOptions(options);
    7.  
    8. QPrinter printer(QPrinter::HighResolution);
    9. QPixmap pixmap(ui.qwtPlot->size());
    10. pixmap.fill(Qt::transparent);
    11.  
    12. if(!pixmap.isNull())
    13. {
    14. QString savingDirectory = QDir::currentPath();
    15. QString fileName = QFileDialog::getSaveFileName(this, tr("Save the file as PDF"),
    16. savingDirectory, tr("(PDF Files)*.pdf"));
    17. QString savingDirectory = strippedPathName(fileName);
    18. if (!fileName.isEmpty())
    19. {
    20. printer.setOutputFormat(QPrinter::PdfFormat);
    21. printer.setOutputFileName(strippedName(fileName));
    22. ui.qwtPlot->print(printer, filter);
    23. QMessageBox::information(this, tr("PDF was saved at..."),
    24. tr("%1 was saved at %2").arg(strippedName(fileName), savingDirectory),
    25. }
    26. }
    27.  
    28. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for any advices.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to change the saving directory of a pdf printed plot?

    From what I see you set only the name of the file using QPrinter::setOutputFileName(), not the whole path (you're using strippedName() there).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    yannwilfried (3rd June 2009)

  4. #3
    Join Date
    Oct 2008
    Location
    Aachen
    Posts
    20
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: How to change the saving directory of a pdf printed plot?

    A whole day to search for a solution . I need to drink more coffee. Many many thanks Wysota.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to change the saving directory of a pdf printed plot?

    Quote Originally Posted by yannwilfried View Post
    I need to drink more coffee.
    No, you need to sleep more
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Qt 4.5.0 install directory change?
    By brcain in forum Installation and Deployment
    Replies: 0
    Last Post: 4th May 2009, 19:58
  2. install help nedded.
    By aj2903 in forum Installation and Deployment
    Replies: 9
    Last Post: 13th November 2008, 07:57
  3. Problem saving a plot
    By kalos80 in forum Qwt
    Replies: 2
    Last Post: 10th July 2008, 08:31
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. saving into a directory
    By Bahar in forum Qt Programming
    Replies: 5
    Last Post: 7th February 2006, 16:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.