Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-2091

Mac OSX Printing with "Save as PDF" never updates filename.

    XMLWordPrintable

Details

    • macOS

    Description

      On Mac / OS X the print dialog provides a PDF button with a "Save as PDF" option.

      The default name provided is the name of the calling window. This works fine the first time the window is called, but subsequent calls to the same QPrinter from applications with different titles (for example different documents in a word processor) all suggest the same name as the first document.

      The only work around is to recreate the QPrinter object each time and this will lose print settings.

      Test case main.cpp to reproduce issue
      ====================================
      #include <QtGui>
      #include <QTextStream>
      #include <QtWebKit>

      //======================================
      class MyWidget: public QWidget
      {
      Q_OBJECT

      public:
      MyWidget(QWidget *parent = 0);

      private slots:
      void doSomething();

      private:
      void print();

      QHBoxLayout *layout;
      QPushButton *button;
      QPrinter *printer;
      int i;
      };
      //======================================
      MyWidget::MyWidget(QWidget *parent) : QWidget(parent)
      {
      setWindowTitle("Name");
      layout = new QHBoxLayout;
      button = new QPushButton ("Do Something");
      layout->addWidget(button);
      setLayout(layout);

      printer = new QPrinter();

      i = 1;
      QObject::connect(button, SIGNAL(clicked()), this, SLOT(doSomething()));
      }
      //======================================
      void MyWidget::doSomething()
      {
      printer->setDocName("BBB");
      print();
      }
      //======================================
      void MyWidget::print()
      {
      QPrintDialog *dlg = new QPrintDialog(printer, this);
      if (dlg->exec() == QDialog::Accepted)

      { QString html; QTextStream stream(&html, QIODevice::WriteOnly); stream << "<html><head><title>This is a title</title></head><body>Printing " << printer->docName() << "</body></html>"; //layout and print table QWebView* layout = new QWebView(); layout->setHtml(html); qApp->processEvents(); layout->page()->mainFrame()->print(printer); delete layout; layout=NULL; }

      delete dlg; dlg=NULL;
      i++;
      setWindowTitle( QString("Name %1").arg );

      //the following does not work either.
      // printer->setOutputFileName( QString("Name %1").arg );
      }
      //======================================
      //This moc name must match the name of the file to get objects into a single file
      #include "main.moc"
      //======================================
      int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);
      MyWidget *myWin = new MyWidget();
      myWin->show();
      return app.exec();
      }
      //======================================

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              johnlayt John Layt
              dettman Dean Dettman (Inactive)
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes