Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Printer bugs on MacOS
Qt 6.11 is out! See what's new in the release blog

Printer bugs on MacOS

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Are there any known bugs or issues to be aware of with Mac Print Drivers for Qt?

    I'm having an issue of an app not being able to print on 1 beta testers machine MacOS 10.5.x & 10.6.x. The tester switched to 10.6.x and the app would print. He then purchased a new printer and the app will not print..but he can print from other apps.

    It works fine on my Mac Mini dev environment (MacOS 10.6.x) and 2 in-house Mac laptops I've tested it on. It works fine on 2 other beta testers machines (MacOS 10.6.x & 10.7.x).

    The print output is just a graphics scene that that gets rendered to a painter device that is a physical printer.

    @
    // scene is built..wait to render it until after the printer has been selected

    // create a printer object and assume it's a physical printer NOT a file
    QPrinter *printer = new QPrinter(QPrinter::HighResolution);

    // the Mac print dialog can't be set to PDF or PS format
    // set printer to a known conditions
    printer->setOutputFormat( QPrinter::NativeFormat );
    printer->setOutputFileName("X");

    // global status bar message
    gsb->showMessage("selecting a printer");
    qApp->processEvents();

    //print issue..works on dev macs(10.6.x), but not on tester's iMac(10.5.8)

    // enum pdWhat { pdHUH=-2, pdREJECTED=-1, pdFINISHED, pdACCEPTED };
    pdstatus = pdHUH;
    pdmsg1 = "";
    pdmsg2 = "";

    QPrintDialog *printDialog = new QPrintDialog( printer, this );

    // hook print dialog signals so we can set progress and result messages
    connect(printDialog, SIGNAL(accepted(QPrinter *)), this, SLOT(PrintAccepted(QPrinter *)));
    connect(printDialog, SIGNAL(rejected()), this, SLOT(PrintRejected()));
    connect(printDialog, SIGNAL(finished(int)), this, SLOT(PrintFinished(int)));

    // if the user clicked PDF in the Mac print dialog, the outputFileName is NOT ""
    int resultofexec = printDialog->exec();

    pdprintername = printer->printerName();
    pdprinterfilename = printer->outputFileName();

    // pdstatus is set by the SLOTs connected to the printDialog
    if ( pdstatus == pdACCEPTED )
    {
    //** print dialog has closed but it will MAGICALLY pipe or direct output to the **
    //** selected destination ONLY if you run through painter->printer code below **
    //
    // PDF redirects to a file ONLY if you run through painter->printer code below
    // if dialog used PDF option..output file name will be != "X" && != ""
    //
    // Preview redirects to printer ONLY if you run through painter->printer code below
    // if dialog used Preview or Print options..output file name will be == ""
    //
    qApp->setOverrideCursor(QCursor( Qt::WaitCursor ));
    // global status bar message
    gsb->showMessage("formatting print output");
    qApp->processEvents();

    // should be OK to initialize
    printer->setFullPage( true );
    
    qreal tm,lm,rm,bm;
    printer->getPageMargins(&lm,&tm,&rm,&bm,QPrinter::Inch);
    
    // adjust the bottom margin..or try to..doh!
    printer->setPageMargins(lm, tm, rm, 0.25, QPrinter::Inch);
    
    // see if the page margin change took effect
    
    // the selected printer as the painter destination
    
    QPainter painter;
    if ( painter.begin( printer ) )
    {
      // able to start the device
      painter.setRenderHint( QPainter::Antialiasing );
      // draw scene to the printer
      scene->render( &painter );
      // tell printer to "go"
      painter.end();
    
      // we've now sent the print output wherever the hell it's going
      if ( pdprinterfilename == "X" )
      {
        // sent to the printer via the print button
        pdmsg1 = "sending print to ";
        pdmsg2 = pdprintername;
      }
      else if ( pdprinterfilename == "" )
      {
        // sent to the printer via the preview button
        pdmsg1 = "showing a preview to ";
        pdmsg2 = pdprintername;
      }
      else
      {
        // print dialog accepted...but really saved to PDF
        pdmsg1 = "printing redirected to ";
        // outputfilename is full path..snag the last section
        pdmsg2 = "'" + pdprinterfilename.section('/', -1) + "'";
      }
    }
    else
    {
      // unable to start printer..we're hosed
      pdmsg2 += "failed at painter.begin";
    }
    

    }
    else
    {
    // print dialog closed with cancel, reject, etc
    }

    qApp->restoreOverrideCursor();
    // leave the message in the status area for ~60 seconds
    gsb->showMessage( "done - " + pdmsg1 + pdmsg2, 1000*60 );
    }

    void PageManager::PrintAccepted( QPrinter * )
    {
    // slot for accept button clicked
    pdstatus = pdACCEPTED;
    pdmsg1 = "OK to print";
    }

    void PageManager::PrintFinished( int result)
    {
    // slot for dialog finished..just eat signal

    pdstatus = pdFINISHED;
    }

    void PageManager::PrintRejected()
    {
    // slot for anything but accept button clicked
    pdstatus = pdREJECTED;
    pdmsg1 = "printing cancelled";
    }

    void PageManager::PrintOther(const QPoint &clickpos )
    {
    // slot for other button clicked
    pdstatus = pdREJECTED;
    pdmsg1 = "printing to PDF or Preview";
    }

    @

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      This code works on the system having the "print problem"..so it appears it may be something associated with "rendering to a painter" code in the previous post...not the Mac Print drivers.

      @
      QString detail;
      QTextStream out(&detail);

      // stream the report in HTML format
      // NOTE: html rules are ignored byt the setHtml function..
      // specifically nested tables are not allowed
      // setting column sizes to a specific % not allowed
      out << "<table width="100%"><caption><b>" + QCoreApplication::applicationName() + "-" + QCoreApplication::applicationVersion() + "</b></caption>";
      out << "<tr><td>User Record Summary for: " << ur->loadedname ;
      out << "</table><hr size=1>";

      QPrinter *printer = new QPrinter(QPrinter::HighResolution);
      printer->setFullPage( true );

      QPrintDialog *printDialog = new QPrintDialog( printer );
      if (printDialog->exec() == QDialog::Accepted)
      {
      printer->setFullPage( true );

      QTextDocument qtd;
      qtd.setHtml( detail );
      qtd.print( printer );
      }

      @

      It doesn't make sense that the render to printer stuff works on most Macs, but one Mac has a problem. Argh!

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LeeWhite2019
        Banned
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved